sendgrid / python-http-client

Twilio SendGrid's Python HTTP Client for calling APIs
https://sendgrid.com
MIT License
125 stars 101 forks source link

Error converting Response.to_dict #86

Closed mdtusz closed 6 years ago

mdtusz commented 6 years ago

Issue Summary

Response.to_dict fails to create dict.

Steps to Reproduce

  1. Make request (in my case, using the sendgrid lib response = sg.client.mail.send.post(request_body=mail.get())
  2. Call response.to_dict

The email successfully is sending and the response is the 202 variant - the error seems to be in deccoding the Response.body.

Stack Trace

Some of the stack has been omitted (things leading up to the response).

Traceback (most recent call last):

  ... stuff leading up to the call

  File "/Users/me/my_file.py", line 48, in general_request
    r = response.to_dict
  File "/Users/me/venv/lib/python3.6/site-packages/python_http_client/client.py", line 55, in to_dict
    return json.loads(self.body.decode('utf-8'))
  File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
thinkingserious commented 6 years ago

Hello @mdtusz,

I've added this to our backlog for a fix. Thanks for reporting it!

The body for a successful email send is empty, so I'm guessing that's the root of the issue.

With Best Regards,

Elmer

thinkingserious commented 6 years ago

The fix will be pushed out in the v3.2.0 release by tomorrow.

See here for the specific fix.

Thanks!