python:如何捕获imaplib.abort?

问题描述 投票:0回答:1

这里是我程序的相关部分:

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

这是错误消息:

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'

因此,如果imaplib没有名为abort的属性,那么self.abort()如何在_check_bye的第929行中引发?

我如何抓住它?

python exception imaplib
1个回答
4
投票

“ [imaplib.abort”行引起误解。实际上,您需要捕获imaplib.IMAP4.abort


0
投票

我和您有同样的问题,您解决了吗?谢谢

© www.soinside.com 2019 - 2024. All rights reserved.