简体   繁体   English

python:我如何捕捉 imaplib.abort?

[英]python: How do I catch imaplib.abort?

Here is the relevant part of my program:这是我的程序的相关部分:

    import imaplib
    ...
    try:
        M.expunge()
        M.close()
        M.logout()
    except imaplib.abort as e:
        print("IMAP abort")

And here is the error message:这是错误消息:

Traceback (most recent call last):
 File "/home/xxx/anaconda3/lib/python3.6/imaplib.py", line 1014, in _command_complete
   typ, data = self._get_tagged_response(tag)
 File "/home/xxx/anaconda3/lib/python3.6/imaplib.py", line 1126, in _get_tagged_response
   self._check_bye()
 File "/home/xxx/anaconda3/lib/python3.6/imaplib.py", line 929, in _check_bye
   raise self.abort(bye[-1].decode(self._encoding, 'replace'))
imaplib.abort: IMAP session state is inconsistent, please relogin.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
 File "mailstats/autoresponder.py", line 224, in <module>
   M.close()
 File "/home/xxx/anaconda3/lib/python3.6/imaplib.py", line 456, in close
   typ, dat = self._simple_command('CLOSE')
 File "/home/xxx/anaconda3/lib/python3.6/imaplib.py", line 1191, in _simple_command
   return self._command_complete(name, self._command(name, *args))
 File "/home/xxx/anaconda3/lib/python3.6/imaplib.py", line 1016, in _command_complete
   raise self.abort('command: %s => %s' % (name, val))
imaplib.abort: command: CLOSE => IMAP session state is inconsistent, please relogin.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
 File "mailstats/autoresponder.py", line 226, in <module>
   except imaplib.abort as e:
AttributeError: module 'imaplib' has no attribute 'abort'

So if imaplib has no attribute called abort , then how is self.abort() being raised in line 929 of _check_bye ?因此,如果 imaplib 没有名为abort属性,那么self.abort()是如何在self.abort()第 929 行_check_bye

How do I catch it?我怎么抓住它?

The " imaplib.abort " line in misleading. imaplib.abort ”行误导。 Actually, you need to catch imaplib.IMAP4.abort .实际上,您需要捕获imaplib.IMAP4.abort

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

相关问题 为什么在正确抓取了10条消息后,会出现Imaplib.abort EOF错误? - Why is there a Imaplib.abort EOF error after 10 correctly crawled messages? 如何在Python中执行IMAP搜索(使用Gmail和imaplib)? - How do I perform an IMAP search in Python (using Gmail and imaplib)? imaplib、imap_tools 几分钟后返回错误。 (imaplib.abort:命令:SELECT =&gt; IMAP4rev1 服务器注销) - imaplib , imap_tools return an error after a few minutes. (imaplib.abort: command: SELECT => IMAP4rev1 Server logging out) 如何增加imaplib请求的超时时间? - How do I increase the timeout for imaplib requests? python imaplib:我只需要调用一次.close()吗? - python imaplib: Do I have to call .close() only once? 如何使用Python imaplib回复电子邮件并包含原始邮件? - How do I reply to an email using the Python imaplib and include the original message? 如何使用Python imaplib为IMAP(Gmail)启用推送通知? - How do I enable push-notification for IMAP (Gmail) using Python imaplib? 如何在Python的imaplib的Gmail IMAP搜索中添加聊天记录? - How do I include chats in a Gmail IMAP search from Python's imaplib? 我如何先登录然后继续通过imaplib和python检查gmail - How do I first login then continue to check gmail via imaplib and python 如何在Python中中止对象实例创建? - How do I abort object instance creation in Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM