2012-12-29 39 views
2

我有一些代碼,獲取IMAP電子郵件和工作完全好了在Python 2.在Python3我得到以下錯誤:的Python 3 imaplib.fetch類型錯誤:不能Concat的字節爲int

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

代碼從return_message功能:

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)]

+0

是'message_id'一個int? –

+0

是的。消息ID來自x =(int(len(id_list)) - int(indexCounter)) – Raymii

回答

4

message_set是一個字符串,而不是一個int。從documentation

The message_set options to commands below is a string specifying one or more messages to be acted upon. It may be a simple message number ('1'), a range of message numbers ('2:4'), or a group of non-contiguous ranges separated by commas ('1:3,6:9'). A range can contain an asterisk to indicate an infinite upper bound ('3:*').

將其轉換爲字符串直接應該足夠:

result, data = mail.fetch(str(message_id), "(RFC822)") 
+0

這樣做了。然而,現在我又遇到了另一個錯誤,我應該在那裏發佈還是創建一個新問題? – Raymii

+1

讓我們來創建一個新帖子,畢竟這是一個新問題。 –

相關問題