sendgrid/sendgrid-python

Sendgrid example breaks with ImportError

jackwardell opened this issue · 1 comments

Issue Summary

I am following these examples:

Code Snippet

# using SendGrid's Python Library
# https://github.com/sendgrid/sendgrid-python
import os
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail

message = Mail(
    from_email='from_email@example.com',
    to_emails='to@example.com',
    subject='Sending with Twilio SendGrid is Fun',
    html_content='<strong>and easy to do anywhere, even with Python</strong>')
try:
    sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
    response = sg.send(message)
    print(response.status_code)
    print(response.body)
    print(response.headers)
except Exception as e:
    print(e.message)

and when running it I get:

Traceback (most recent call last):
  File "/home/jack/src/test/venv/lib/python3.8/site-packages/sendgrid/helpers/mail/email.py", line 2, in <module>
    import rfc822
ModuleNotFoundError: No module named 'rfc822'

During handling of the above exception, another exception occurred:

### Exception/Log
Traceback (most recent call last):
  File "/home/jack/src/test/email.py", line 5, in <module>
    from sendgrid import SendGridAPIClient
  File "/home/jack/src/test/venv/lib/python3.8/site-packages/sendgrid/__init__.py", line 19, in <module>
    from .helpers.mail import *  # noqa
  File "/home/jack/src/test/venv/lib/python3.8/site-packages/sendgrid/helpers/mail/__init__.py", line 4, in <module>
    from .bcc_email import Bcc
  File "/home/jack/src/test/venv/lib/python3.8/site-packages/sendgrid/helpers/mail/bcc_email.py", line 1, in <module>
    from .email import Email
  File "/home/jack/src/test/venv/lib/python3.8/site-packages/sendgrid/helpers/mail/email.py", line 4, in <module>
    import email.utils as rfc822
  File "/home/jack/src/test/email.py", line 5, in <module>
    from sendgrid import SendGridAPIClient
ImportError: cannot import name 'SendGridAPIClient' from partially initialized module 'sendgrid' (most likely due to a circular import) (/home/jack/src/test/venv/lib/python3.8/site-packages/sendgrid/__init__.py)

Technical details:

OS: Ubuntu 20.04
Python: 3.8.10
Sendgrid: 6.8.0

In the docs it says: "Our library requires Python 2.6, 2.7, 3.4 or 3.5."

Is this simply incompatibility with 3.8?

Thanks

You can delete this issue. Turns out you can't name a the file email.py.