1
我有一個腳本如下蟒蛇未能導入的smtplib
#!/usr/bin/python
import smtplib
import datetime
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
now = '{:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now())
fromaddr = "[email protected]"
toaddr = "[email protected]"
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "Device Start Up Notification"
body = "Your device is started up %s " % now
msg.attach(MIMEText(body, 'plain'))
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(fromaddr, "abc12345")
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
server.quit()
當我執行這個文件,它會顯示錯誤
Traceback (most recent call last):
File "./email.py", line 2, in <module>
import smtplib
File "/usr/lib/python2.7/smtplib.py", line 46, in <module>
import email.utils
File "/home/jypang/email.py", line 4, in <module>
from email.MIMEMultipart import MIMEMultipart
ImportError: No module named MIMEMultipart
庫被安裝,因爲我有另一個腳本相同上面的腳本(導入相同的庫),它運行良好。
請協助,謝謝!
感謝您抽出寶貴的教訓!也必須刪除email.pyc –