我尝试运行以下代码(命名为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)
这是错误:
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'
但是,当我在解释器中输入代码时,它会运行。
怎么了?