Partially initialized module, Circular Import Error
aarontgit opened this issue · 3 comments
Issue Summary
I am trying to integrate SendGrid using the WebAPI with Python, however I keep getting this error message: 'cannot import name 'SendGridAPIClient' from partially initialized module 'sendgrid' (most likely due to a circular import)'
Steps to Reproduce
- This is the first step
- This is the second step
- Further steps, etc.
Code Snippet
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)
Exception/Log
# paste exception/log here
Technical details:
- sendgrid-python version:
- python version: 3.9.1
Is your python filename along the lines email.py
or sendgrid.py
? Try changing it to something else.
Is your python filename along the lines
email.py
orsendgrid.py
? Try changing it to something else.
That worked. However, I am now receiving a 'UnauthorizedError: HTTP Error 401: Unauthorized'
Thanks for helping out @rlSimonLi!
@aarontgit please check that your environment variable SENDGRID_API_KEY
is set correctly and that os.environ.get('SENDGRID_API_KEY')
is returning the right value. If so, then there may be an issue with your account (in that case, please reach out to https://support.sendgrid.com). Thank you!