Reputation: 165
I tried running the following code (named as email.py
):
import smtplib
GMAIL_USERNAME = raw_input("Enter your username: ")
GMAIL_PASSWORD = raw_input("Enter your password: ")
session = smtplib.SMTP('smtp.gmail.com', 587)
session.ehlo()
session.starttls()
session.login(GMAIL_USERNAME, GMAIL_PASSWORD)
This is the error:
Traceback (most recent call last):
File "email.py", line 1, in <module>
import smtplib
File "/usr/lib/python2.7/smtplib.py", line 46, in <module>
import email.utils
File "/home/sourya/VProgramming/projects/email.py", line 6, in <module>
session = smtplib.SMTP('smtp.gmail.com', 587)
AttributeError: 'module' object has no attribute 'SMTP'
However, the code does run when I type it out in the interpreter.
What's wrong?
Upvotes: 1
Views: 2246
Reputation: 65791
Try renaming you script (to something other than email.py
).
email
is a Python module, but your script's name shadows it, and it can't be imported.
Note: Don't forget to remove email.pyc
as well.
Upvotes: 4