#29621: Different Http requests behaviour between python shell and Django shell
-------------------------------------+-------------------------------------
               Reporter:  Zaghbane   |          Owner:  nobody
  Safiy Errahmane                    |
                   Type:  Bug        |         Status:  new
              Component:             |        Version:  2.0
  Uncategorized                      |       Keywords:  #manager_shell
               Severity:  Normal     |  #requests
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 == Issue Summary

 I’m using the sendgrid api to add recipients, the server response is good,
 though nothing is added. and thats because i’m using Django manager shell.

 == Steps to Reproduce

 I used this script to add the recipient:

 {{{
 import sendgrid
 service = sendgrid.SendGridAPIClient(apikey=API_KEY)
 response = service.client.contactdb.recipients.post(
    request_body=[{
        'created': 1234543,
        'email': '[email protected]',
        'first_name': 'John',
        'last_name': '',
        'gender': 'M',
    }]
 )
 print(response.status_code)
 201
 print(response.body)

 
'{"new_count":1,"updated_count":0,"error_count":0,"error_indices":[],"unmodified_indices":[],"persisted_recipients":["dG90b0B0dXQuY29t"],"errors":[]}\n'

 print(response.headers)

 {'Server': 'nginx', 'Date': 'Wed, 01 Aug 2018 08:34:11 GMT', 'Content-
 Type': 'application/json', 'Content-Length': '149', 'Connection': 'keep-
 alive', 'Access-Control-Allow-Methods': 'HEAD, GET, PUT, POST, DELETE,
 OPTIONS, PATCH', 'Access-Control-Max-Age': '21600', 'Access-Control-
 Expose-Headers': 'Link, Location', 'Access-Control-Allow-Origin': '*',
 'Access-Control-Allow-Headers': 'AUTHORIZATION, Content-Type, On-behalf-
 of, x-sg-elas-acl, X-Recaptcha', 'Content-Security-Policy': "default-src
 https://api.sendgrid.com; frame-src 'none'; object-src 'none'", 'X
 -Content-Type-Options': 'nosniff', 'Strict-Transport-Security': 'max-
 age=31536000', 'X-Ratelimit-Remaining': '2', 'X-Ratelimit-Limit': '3', 'X
 -Ratelimit-Reset': '1533112452', 'Powered-By': 'Mako'}
 }}}

 I checked if it is added .. and nothing was added

 I tried the same thing with postman, and everything worked normally with
 no problem, and i found the recipient.

 After I tried with requests

 {{{
 import requests
 url = 'https://api.sendgrid.com/v3/contactdb/recipients'
 headers = {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer %s' % API_KEY,
    'Cache-Control': 'no-cache',
 }
 data = json.dumps([{
    'created': 1234543,,
    'email': '[email protected]',
    'first_name': 'John',
    'last_name': '',
    'gender': 'M',
 }])
 response = requests.post(url, headers=headers, data=data)
 response

 <Response [201]>

 response.text

 
'{"new_count":1,"updated_count":0,"error_count":0,"error_indices":[],"unmodified_indices":[],"persisted_recipients":["ZXhhbXBsZUBleGFtcGxlLmNvbQ=="],"errors":[]}\n'
 }}}

 Again .. nothing was added.

 and all this time I was running these scripts in Django manager shell in
 dev mode,
 after when I used the same scripts in python shell, it works correctly,
 and I recipient is added, so I have no idea whats going on !!!!!

 I also tried with Django manager shell in prod mode, same problem !

 NB: The problem also occurs on celery workers with Django code.

 == Technical details

 * sendgrid-python Version: 5.4.1
 * Python Version: 3.7
 * Django Version: 2.0.7

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29621>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/052.277dab099069751a97f30545008b4343%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to