gpt4 book ai didi

python - imaplib.error : command SEARCH illegal in state AUTH, 只允许在已选择的状态下使用

转载 作者:太空宇宙 更新时间:2023-11-03 13:12:46 33 4
gpt4 key购买 nike

def connect_imap():
m = imaplib.IMAP4_SSL("imap.gmail.com", 993)
print("{0} Connecting to mailbox via IMAP...".format(datetime.datetime.today().strftime("%Y-%m-%d %H:%M:%S")))
details = login_credentials()
m.login(details[0], details[1])
return m


m = connect_imap()
typ, data = m.search(None, 'ALL')
m.close()
m.logout()

上面代码的输出是:

2016-08-24 10:55:34 Connecting to mailbox via IMAP...
Traceback (most recent call last):
File "/home/zoikmail/Desktop/test.py", line 25, in <module>
typ, data = m.search(None, 'ALL')
File "/usr/lib/python2.7/imaplib.py", line 640, in search
typ, dat = self._simple_command(name, *criteria)
File "/usr/lib/python2.7/imaplib.py", line 1088, in _simple_command
return self._command_complete(name, self._command(name, *args))
File "/usr/lib/python2.7/imaplib.py", line 838, in _command
', '.join(Commands[name])))
imaplib.error: command SEARCH illegal in state AUTH, only allowed in states SELECTED
[Finished in 1.2s with exit code 1]
[shell_cmd: python -u "/home/zoikmail/Desktop/test.py"]
[dir: /home/zoikmail/Desktop]
[path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games]

上面的代码有什么问题?

最佳答案

您需要在成功连接到 IMAP-Server 后选择一个邮箱。使用

m.select()

连接之后和搜索之前。

关于python - imaplib.error : command SEARCH illegal in state AUTH, 只允许在已选择的状态下使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39115141/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com