錯誤被拋出是:如何捕捉Python的SMTPlib中的連接超時錯誤?
error: [Errno 110] Connection timed out
我不知道該怎麼除?
try:
smtpObj = smtplib.SMTP('smtp.example.com')
smtpObj.starttls()
smtpObj.login('user','pass')
smtpObj.sendmail(sender, receivers, message)
print "Successfully sent email"
except smtplib.SMTPException('Error: unable to send email"'):
pass
except smtplib.socket.error ('Error: could not connect to server'):
pass
謝謝。
你可以發佈引發錯誤的代碼嗎? – 2010-03-28 03:23:59
我用引發錯誤的代碼更新了問題。它會在無法聯繫到smtp服務器時拋出錯誤。 – ensnare 2010-03-28 03:38:52