繁体   English   中英

使用 imap_tools 批量获取电子邮件时出现“EOF 错误” python

[英]"EOF error" when fetching emails in bulk using imap_tools python

我构建了一个非常简单的脚本,用于从 Outlook 收件箱中提取电子邮件。 它看起来像这样:

from imap_tools import MailBox

inbox = MailBox("outlook.office365.com").login("email", "password")

for email in inbox.fetch():  # bulk=True
    print(email)

当我这样使用它时它正在工作。 但是,当在fetch() function 上传递 arg bulk=True时,它会引发以下错误:

Traceback (most recent call last):
  File "/Users/julius/Library/Application Support/JetBrains/IntelliJIdea2022.3/scratches/scratch_1.py", line 5, in <module>
    for email in inbox.fetch(bulk=True):
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/imap_tools/mailbox.py", line 171, in fetch
    for fetch_item in (self._fetch_in_bulk if bulk else self._fetch_by_one)(nums, message_parts, reverse):  # noqa
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/imap_tools/mailbox.py", line 144, in _fetch_in_bulk
    fetch_result = self.client.fetch(','.join(message_nums), message_parts)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/imaplib.py", line 548, in fetch
    typ, dat = self._simple_command(name, message_set, message_parts)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/imaplib.py", line 1230, in _simple_command
    return self._command_complete(name, self._command(name, *args))
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/imaplib.py", line 1008, in _command
    raise self.abort('socket error: %s' % val)
imaplib.IMAP4.abort: socket error: EOF occurred in violation of protocol (_ssl.c:2396)

有没有人知道如何解决这个问题?

正确答案:结合bulklimit args。

来自文档的文本:对于具有大量消息的操作,imap 命令可能太大并且会在服务器端导致异常,在这种情况下使用“limit”参数进行提取。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM