You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With the latest release (6.8.0 as of this writing), this section of the quick start no longer works. The order of the parameters must be fixed or specify the arguments' name for each one.
Steps to Reproduce
Attempt to follow the instructions described in this section to send a basic email.
This error raises, due to the mismatch of the arguments' order: TypeError: Object of type Content is not JSON serializable
Can be fixed by specifying the name for each argument like this:
mail = Mail(from_email=from_email, to_emails=to_email, subject=subject, plain_text_content=content)
Code Snippet
importsendgridimportosfromsendgrid.helpers.mailimport*sg=sendgrid.SendGridAPIClient(api_key=os.environ.get('SENDGRID_API_KEY'))
from_email=Email("[email protected]")
to_email=To("[email protected]")
subject="Sending with SendGrid is Fun"content=Content("text/plain", "and easy to do anywhere, even with Python")
mail=Mail(from_email, to_email, subject, content)
response=sg.client.mail.send.post(request_body=mail.get())
print(response.status_code)
print(response.body)
print(response.headers)
Exception/Log
Traceback (most recent call last):
File "/Users/francisco/debugging/email_test.py", line 6896, in <module>
response = sg.client.mail.send.post(request_body=mail.get())
File "/Users/francisco/opt/anaconda3/lib/python3.8/site-packages/python_http_client/client.py", line 257, in http_request
data = json.dumps(request_body).encode('utf-8')
File "/Users/francisco/opt/anaconda3/lib/python3.8/json/__init__.py", line 231, in dumps
return _default_encoder.encode(obj)
File "/Users/francisco/opt/anaconda3/lib/python3.8/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/Users/francisco/opt/anaconda3/lib/python3.8/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "/Users/francisco/opt/anaconda3/lib/python3.8/json/encoder.py", line 179, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type Content is not JSON serializable
[Finished in 0.3s with exit code 1]
Technical details:
sendgrid-python version: sendgrid-6.8.0
python version: Python 3.8.3
The text was updated successfully, but these errors were encountered:
Issue Summary
With the latest release (6.8.0 as of this writing), this section of the quick start no longer works. The order of the parameters must be fixed or specify the arguments' name for each one.
Steps to Reproduce
TypeError: Object of type Content is not JSON serializable
Code Snippet
Exception/Log
Technical details:
The text was updated successfully, but these errors were encountered: