突然,我连接到gmail并检查未读电子邮件的代码停止工作:
Connecting to Inbox..
Error
Traceback (most recent call last):
File "./run", line 27, in <module>
mail.login("xxx@dddd.com", "xxxxx123")
File "/usr/lib/python2.6/imaplib.py", line 498, in login
typ, dat = self._simple_command('LOGIN', user, self._quote(password))
File "/usr/lib/python2.6/imaplib.py", line 1060, in _simple_command
return self._command_complete(name, self._command(name, *args))
File "/usr/lib/python2.6/imaplib.py", line 890, in _command_complete
raise self.abort('command: %s => %s' % (name, val))
imaplib.abort: command: LOGIN => socket error: EOF
以下是代码:
#!/usr/bin/env python
import imaplib, re
import os
import time
import socket
imap_host = 'imap.gmail.com'
mail = imaplib.IMAP4_SSL(imap_host, 993)
mail.login("xxxx@xxxx.com", "xxxx")
while True:
try:
print 'Connecting to Inbox..'
mail.select("inbox") # connect to inbox.
result, data = mail.uid('search', None, 'UNSEEN')
uid_list = data[0].split()
print len(uid_list), 'Unseen emails.'
if len(uid_list) > 20:
os.system('heroku restart --app xxx-xx-203')
time.sleep(30)
except:
print 'Error'
time.sleep(120)
imap_host = 'imap.gmail.com'
mail = imaplib.IMAP4_SSL(imap_host, 993)
mail.login("xxx@xxx.com", "xxxx")
pass
我也经常犯这个错误:
Traceback (most recent call last):
File "./run", line 10, in <module>
mail.login("xxx@xxx.com", "xxx")
File "/usr/lib/python2.6/imaplib.py", line 498, in login
typ, dat = self._simple_command('LOGIN', user, self._quote(password))
File "/usr/lib/python2.6/imaplib.py", line 1060, in _simple_command
return self._command_complete(name, self._command(name, *args))
File "/usr/lib/python2.6/imaplib.py", line 893, in _command_complete
self._check_bye()
File "/usr/lib/python2.6/imaplib.py", line 808, in _check_bye
raise self.abort(bye[-1])
imaplib.abort: [UNAVAILABLE] Temporary System Error
答案 0 :(得分:0)
怪异。我跑了你确切的代码并连接到gmail就好了。我建议尝试从另一个系统连接。
如果您无法访问任何其他系统,我可以为您提供帐户,如果您愿意,可以尝试使用。
答案 1 :(得分:0)
这必将最终发生。解决方案是捕获中止异常并重新初始化您的imap连接。