本文介绍了Python IMAP4选择邮箱名称包含空格字符,错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Python imaplib.IMAP4
连接到Google电子邮件.除我使用包含空格字符的邮箱名称的IMAP4.select()
方法外,其他所有操作都可以.假设我的邮箱名称是"Gama Sutra".
I am using Python imaplib.IMAP4
to connect to Google email. Every thing is okay except when I use IMAP4.select()
method using a mailbox name that contains a space character. Let's say my mailbox name is "Gama Sutra".
当我执行imap.select('[Gmail]/Gama Sutra')
时,会出现此错误:
When I execute imap.select('[Gmail]/Gama Sutra')
it gives me this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/imaplib.py", line 682, in select
typ, dat = self._simple_command(name, mailbox)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/imaplib.py", line 1133, in _simple_command
return self._command_complete(name, self._command(name, *args))
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/imaplib.py", line 964, in _command_complete
raise self.error('%s command error: %s %s' % (name, typ, data))
imaplib.error: SELECT command error: BAD [b'Could not parse command']
我该如何解决?
推荐答案
它应该自动执行此操作,但只需将文件夹名称用双引号引起来即可:
It should do this automatically, but simply surround your folder name in double quotes:
imap.select('"[Gmail]/Gama Sutra"')
这篇关于Python IMAP4选择邮箱名称包含空格字符,错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!