sendgrid-python: ImportError: cannot import name 'SendGridAPIClient'
Issue Summary
A summary of the issue and the environment in which it occurs. If suitable, include the steps required to reproduce the bug. Please feel free to include screenshots, screencasts, code examples.
I pip install the sendgrid.

I just follow your guide in this link https://app.sendgrid.com/guide/integrate/langs/python and when I run the example code following, I get the error below
python version: Python 3.6.1 :: Anaconda custom (64-bit). computer: mac10.14 CODE
# 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='support@buzzbreak.news',
to_emails='support@buzzbreak.news',
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)
ERROR
Traceback (most recent call last):
File "/Users/mabodx/anaconda/lib/python3.6/site-packages/python_http_client/client.py", line 7, in <module>
import urllib.request as urllib
File "/Users/mabodx/anaconda/lib/python3.6/urllib/request.py", line 86, in <module>
import email
File "/Users/mabodx/code/Paritko/anguis/email/email.py", line 4, in <module>
from sendgrid import SendGridAPIClient
ImportError: cannot import name 'SendGridAPIClient'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "email.py", line 4, in <module>
from sendgrid import SendGridAPIClient
File "/Users/mabodx/anaconda/lib/python3.6/site-packages/sendgrid/__init__.py", line 19, in <module>
from .sendgrid import SendGridAPIClient # noqa
File "/Users/mabodx/anaconda/lib/python3.6/site-packages/sendgrid/sendgrid.py", line 19, in <module>
import python_http_client
File "/Users/mabodx/anaconda/lib/python3.6/site-packages/python_http_client/__init__.py", line 1, in <module>
from .client import Client # noqa
File "/Users/mabodx/anaconda/lib/python3.6/site-packages/python_http_client/client.py", line 12, in <module>
import urllib2 as urllib
ModuleNotFoundError: No module named 'urllib2'
Steps to Reproduce
- This is the first step run this example code
# 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)```
2. This is the second step
3. Further steps, etc.
Any other information you want to share that is relevant to the issue being reported. Especially, why do you consider this to be a bug? What do you expect to happen instead?
#### Technical details:
* sendgrid-python Version: master (latest commit: [commit number])
* Python Version: 3.6.1
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 15 (4 by maintainers)
Can you try renaming your file from
email.pytoemail_test.py?WHY? why does renaming it work??
Thank you for the response. When I run the import from the python interpreter they work. But if I run the code in the python file I still get the error: Code (email.py)
When I run on the console I get:
Python Version: Anaconda (Python 3.6.6)
incredible. I have renamed my file “sendgrid.py” to “mail.py” and the issue stopped )))))
Renaming my python file for email.py to email_test.py stopped this issues happening