嗨我突然在一些代码上使用imaplib时遇到错误。之前工作正常。
import imaplib
m = imaplib.IMAP4('myserver','port')
m.login(r'username','password')
m.select()
给我错误
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/imaplib.py", line 649, in select
typ, dat = self._simple_command(name, mailbox)
File "/usr/lib/python2.7/imaplib.py", line 1070, in _simple_command
return self._command_complete(name, self._command(name, *args))
File "/usr/lib/python2.7/imaplib.py", line 899, in _command_complete
raise self.abort('command: %s => %s' % (name, val))
imaplib.abort: command: SELECT => unexpected response: '* 1520 EXISTS'
我不确定这意味着什么。电子邮件正好通过,我正在使用davmail作为服务器。
整个程序会在特定文件夹中保存具有特定名称的附件。
我已经介入了它,它绝对是m.select()
,它正在垮掉。
这个程序直到最近一直很好。
我做错了什么,我该如何解决?
活动日志如下
>>> import imaplib
>>> m = imaplib.IMAP4('server','port')
>>> Debug=4
>>> m.debug
0
>>> m.debug=4
>>> m.debug
4
>>> m.login(r'username','password')
01:26.55 > HLFI1 LOGIN "username" "password"
01:30.76 < HLFI1 OK Authenticated
('OK', ['Authenticated'])
>>> m.list()
01:56.33 > HLFI2 LIST "" *
02:00.04 < * LIST (\HasNoChildren) "/" "Trash/Sent Messages"
02:00.04 < * LIST (\HasNoChildren) "/" "Sync Issues/Server Failures"
02:00.04 < * LIST (\HasNoChildren) "/" "Sync Issues/Local Failures"
02:00.04 < * LIST (\HasNoChildren) "/" "Sync Issues/Conflicts"
02:00.04 < * LIST (\HasChildren) "/" "Sync Issues"
02:00.04 < * LIST (\HasNoChildren) "/" "Junk E-mail"
02:00.04 < * LIST (\HasNoChildren) "/" "Drafts"
02:00.04 < * LIST (\HasChildren) "/" "Trash"
02:00.04 < * LIST (\HasNoChildren) "/" "Sent"
02:00.04 < * LIST (\HasNoChildren) "/" "Outbox"
02:00.04 < * LIST (\HasNoChildren) "/" "INBOX"
02:00.04 < HLFI2 OK LIST completed
('OK', ['(\\HasNoChildren) "/" "Trash/Sent Messages"', '(\\HasNoChildren) "/" "Sync Issues/Server Failures"', '(\\HasNoChildren) "/" "Sync Issues/Local Failures"', '(\\HasNoChildren) "/" "Sync Issues/Conflicts"', '(\\HasChildren) "/" "Sync Issues"', '(\\HasNoChildren) "/" "Junk E-mail"', '(\\HasNoChildren) "/" "Drafts"', '(\\HasChildren) "/" "Trash"', '(\\HasNoChildren) "/" "Sent"', '(\\HasNoChildren) "/" "Outbox"', '(\\HasNoChildren) "/" "INBOX"'])
>>> m.select()
02:21.37 > HLFI3 SELECT INBOX
02:30.87 < * 1548 EXISTS
02:30.87 last 4 IMAP4 interactions:
00:16.73 < * OK [CAPABILITY IMAP4REV1 AUTH=LOGIN MOVE] IMAP4rev1 DavMail 4.3.0-2125 server ready
00:16.73 > HLFI0 CAPABILITY
00:16.74 < * CAPABILITY IMAP4REV1 AUTH=LOGIN MOVE
00:16.77 < HLFI0 OK CAPABILITY completed
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/imaplib.py", line 649, in select
typ, dat = self._simple_command(name, mailbox)
File "/usr/lib/python2.7/imaplib.py", line 1070, in _simple_command
return self._command_complete(name, self._command(name, *args))
File "/usr/lib/python2.7/imaplib.py", line 899, in _command_complete
raise self.abort('command: %s => %s' % (name, val))
imaplib.abort: command: SELECT => unexpected response: '* 1548 EXISTS'
**更新**
我现在已经在
下的python-dev上提交了一个错误David Murray表示响应不符合RFC
在
下的davmail sourceforge上的第二个M猜测说IMAP必须保持活着。
我会随着发展情况保持最新状态。
答案 0 :(得分:1)
RECENT
响应中的空格填充消息计数似乎触发了这一点。我不清楚它是否应该被归类为Python imaplib
或您正在使用的IMAP服务器中的错误。我认为imaplib
应该是强有力的,不管规范是什么。也许您应该提交错误报告?
(如果你这样做,请注意添加有关哪个服务器正在产生此响应的详细信息。如果它是具有可观市场份额的商业产品,那么修复是很重要的,当然,如果它是你自己的简单Python服务器,他们可能不在乎。)
答案 1 :(得分:1)
发现EXISTS
命令的响应由davmail
填充,这似乎是电子邮件数量约为500或超过500时。
可接受的答复:
58:24.54 > PJJD3 EXAMINE INBOX
58:24.77 < * 486 EXISTS
58:24.78 matched r'\* (?P<data>\d+) (?P<type>[A-Z-]+)( (?P<data2>.*))?' => ('486', 'EXISTS', None, None)
58:24.78 untagged_responses[EXISTS] 0 += ["486"]
失败的响应:
57:50.86 > KPFE3 EXAMINE INBOX
57:51.10 < * 953 EXISTS
57:51.10 last 0 IMAP4 interactions:
57:51.10 > KPFE4 LOGOUT
已为github的imaplib
库创建了一个提取请求,以解决该问题
要修补代码,imaplib
允许更改正则表达式,只需在代码中添加以下内容即可:
imaplib.Untagged_status = imaplib.re.compile(br'\*[ ]{1,2}(?P<data>\d+) (?P<type>[A-Z-]+)( (?P<data2>.*))?')