Opened 6 years ago

Closed 6 years ago

#29621 closed Bug (needsinfo)

Different Http requests behaviour between python shell and Django shell

Reported by: Zaghbane Safiy Errahmane Owned by: nobody
Component: Uncategorized Version: 2.0
Severity: Normal Keywords: #manager_shell #requests
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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': 'test@test.co',
       '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': 'test@test.co',
   '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

Change History (1)

comment:1 by Tim Graham, 6 years ago

Resolution: needsinfo
Status: newclosed

You need to debug the issue yourself and explain why Django is at fault. If you can't do that, then you could try asking for help in our support channels.

Note: See TracTickets for help on using tickets.
Back to Top