Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Latest version breaks Quick Start Guide and possibly other documentation. #1001

Closed
MrPanchoso opened this issue Aug 14, 2021 · 1 comment · Fixed by #1003
Closed

Latest version breaks Quick Start Guide and possibly other documentation. #1001

MrPanchoso opened this issue Aug 14, 2021 · 1 comment · Fixed by #1003

Comments

@MrPanchoso
Copy link

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

  1. Attempt to follow the instructions described in this section to send a basic email.
  2. This error raises, due to the mismatch of the arguments' order:
    TypeError: Object of type Content is not JSON serializable
  3. 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

import sendgrid
import os
from sendgrid.helpers.mail import *

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
@poctob
Copy link

poctob commented Aug 17, 2021

Also reproducible with:
sendgrid-6.8.0
Python 3.9.1

Downgrading to sendgrid-6.7.1 resolves the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants