sendgrid-python icon indicating copy to clipboard operation
sendgrid-python copied to clipboard

ImportError: No module named helpers.mail

Open ervaibhavsinghal opened this issue 9 years ago • 14 comments

Issue Summary

ImportError: No module named helpers.mail when I'm run this code on my machine. i've followed all steps which are described in the Integration kit.

Sample Code:

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

sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) from_email = Email("[email protected]") to_email = Email("[email protected]") subject = "Sending with SendGrid is Fun" content = Content("text/plain", "and easy to do anywhere, even with Python") mail = Mail(from_email, subject, to_email, content) response = sg.client.mail.send.post(request_body=mail.get()) print(response.status_code) print(response.body) print(response.headers)

Technical details:

  • sendgrid-python Version: 5.0.0
  • Python Version: 2.7.6

ervaibhavsinghal avatar Aug 14 '17 00:08 ervaibhavsinghal

Hello @ervaibhavsinghal,

Unfortunately, I can not reproduce this. Here are the steps I took:

mkdir test5
cd test5
virtualenv env
source env/bin/activate
pip install sendgrid

Then I created test.py with the code provided above and added my own emails.

python test.py

And the email was sent.

Please review and let me know if there are any differences in our setup.

Thanks!

With Best Regards,

Elmer

thinkingserious avatar Aug 14 '17 15:08 thinkingserious

@thinkingserious I've already used these steps and faced this issue.

ervaibhavsinghal avatar Aug 14 '17 21:08 ervaibhavsinghal

Hi @ervaibhavsinghal,

Can you please try retracing and logging your steps so I can compare with mine?

Also, what operating system are you using?

With Best Regards,

Elmer

thinkingserious avatar Aug 15 '17 19:08 thinkingserious

@thinkingserious actually I'm working on node js API but this is not working, so I thought to test the same API in python, it's working now in a python. Thanks but in node it's not working.

ervaibhavsinghal avatar Aug 16 '17 07:08 ervaibhavsinghal

Hello, having the exact same issue !

I am able to run the same code find on a VM on OS X. But on our ububunt 16 machine I have the same error. I did pip uinstall sendgrid and then pip install sendgrid to make sure current version ...

ra-esmith avatar Dec 09 '17 11:12 ra-esmith

Oddly if I run python by hand I do not see the issue, only when I run my script ...

ra-esmith avatar Dec 09 '17 11:12 ra-esmith

ok issue was naturally my environment variable PATH which had some things out of order. Once I sorted that out all worked. I suggest folks clear the PATH variable and add stuff back in slowly once they get send grid working. standard type of issue

ra-esmith avatar Dec 09 '17 12:12 ra-esmith

Awesome, I'm glad you got it sorted and thanks for following up!

thinkingserious avatar Dec 14 '17 02:12 thinkingserious

Just ran into this issue and it was driving me crazy. I could not figure out why this was happening. Fast forward 2 hours later when I realized that I made the mistake of naming my file sendgrid.py

giphy-2

Everything works when you name your file anything else - in case anyone runs into the same issue.

Thanks for all the great work on this library - much appreciated!!

dace avatar Feb 11 '18 07:02 dace

Thank you @hidace!

thinkingserious avatar Feb 14 '18 20:02 thinkingserious

hhaha, my file name is "sendgrid.py" and this is the reason

belary avatar Aug 06 '18 06:08 belary

Same issue!

Runs ok on a virtualenv fwiw

Installing collected packages: python-http-client, sendgrid Running setup.py install for python-http-client ... done Successfully installed python-http-client-3.1.0 sendgrid-5.6.0 ➜ ✗ pip freeze | grep sendgrid sendgrid==5.6.0 ➜ git:(master) ✗ python3
Type "help", "copyright", "credits" or "license" for more information.

import sendgrid Traceback (most recent call last): File "", line 1, in ModuleNotFoundError: No module named 'sendgrid'

kotharitrisha avatar Oct 25 '18 04:10 kotharitrisha

Just ran into this issue and it was driving me crazy. I could not figure out why this was happening. Fast forward 2 hours later when I realized that I made the mistake of naming my file sendgrid.py

giphy-2

Everything works when you name your file anything else - in case anyone runs into the same issue.

Thanks for all the great work on this library - much appreciated!!

SAME HERE!!!!

davidtavarez avatar Dec 13 '18 22:12 davidtavarez

Just ran into this issue and it was driving me crazy. I could not figure out why this was happening. Fast forward 2 hours later when I realized that I made the mistake of naming my file sendgrid.py giphy-2 Everything works when you name your file anything else - in case anyone runs into the same issue. Thanks for all the great work on this library - much appreciated!!

SAME HERE!!!!

Can i suggest a line at the top of the file to save people trying it some headache.

assert __file__ != "sendgrid.py", "Err: Can't call your script the same as the sendgrid.py module"

diepes avatar Mar 26 '19 04:03 diepes