1
當我想知道失敗爲何這段代碼蟒蛇:發送郵件,裏面是「與」塊
test = smtplib.SMTP('smtp.gmail.com', 587)
test.ehlo()
test.starttls()
test.ehlo()
test.login('address','passw')
test.sendmail(sender, recipients, composed)
test.close()
作品,但是當這樣寫的
with smtplib.SMTP('smtp.gmail.com', 587) as s:
s.ehlo()
s.starttls()
s.ehlo()
s.login('address','passw')
s.sendmail(sender, recipients, composed)
s.close()
它失敗的消息
Unable to send the email. Error: <class 'AttributeError'>
Traceback (most recent call last):
File "py_script.py", line 100, in <module>
with smtplib.SMTP('smtp.gmail.com', 587) as s:
AttributeError: __exit__
這是爲什麼發生? (在樹莓派上的python3) Thx
然後這是錯誤的(?)http://robertwdempsey.com/python3-email-with-attachments-using-gmail/ – Gerard
但在python3?我在版本3中嘗試它編輯:好的,我有python 3.2.3,謝謝:) – Gerard
@Gerard:文檔說明它是在Python 3.3中作爲上下文管理器。 –