我有一些获取IMAP电子邮件的代码,在Python 2中运行得非常好。在Python3中,我得到以下错误:
Traceback (most recent call last):
File "./mail.py", line 295, in
item=return_message(x)
File "./mail.py", line 122, in return_message
result, data = mail.fetch(message_id, "(RFC822)")
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/imaplib.py", line 460, in fetch
typ, dat = self._simple_command(name, message_set, message_parts)
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/imaplib.py", line 1113, in _simple_command
return self._command_complete(name, self._command(name, *args))
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/imaplib.py", line 883, in _command
data = data + b' ' + arg
TypeError: can't concat bytes to int
返回消息函数中的代码:
result, data = mail.fetch(message_id, "(RFC822)")
raw_email = data[0][1]
email_message = email.message_from_string(raw_email)
运行时信息:
3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 01:25:11)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]
message_set
是字符串,而不是int。从documentation:直接将其转换为字符串就足够了:
相关问题 更多 >
编程相关推荐