我从使用Python3.3上的poplib的代码中得到了一个错误,但它适用于Python2.7:
poplib.error_proto: b"-ERR Invalid message number: b'1'"我想迁移到python3.3,因为我有一个只安装在python3.3上的特定模块。
我正在学习python编程语言。
下面是在python2.7上成功的示例,但是这个示例代码不能在我的python 3.3上工作。
import poplib
pop_server = 'mail01.org'
user = 'user'
password = 'pass'
p = poplib.POP3(pop_server)
p.user(user)
p.pass_(password)
print ("This mailbox has %d messages, totaling %d bytes." % p.stat())
msg_list = p.list()
print (msg_list)
for msg in msg_list[1]:
msg_num, _ = msg.split()
resp = p.retr(msg_num)这是输出:
This mailbox has 2 messages, totaling 633300 bytes.
(b'+OK 2 messages:', [b'1 137956', b'2 495344'], 20)以下是错误跟踪:
Traceback (most recent call last):
File "AttachmentDownloader.py", line 28, in <module>
resp = p.retr(msg_num)
File "C:\Python33\lib\poplib.py", line 236, in retr
return self._longcmd('RETR %s' % which)
File "C:\Python33\lib\poplib.py", line 171, in _longcmd
return self._getlongresp()
File "C:\Python33\lib\poplib.py", line 147, in _getlongresp
resp = self._getresp()
File "C:\Python33\lib\poplib.py", line 140, in _getresp
raise error_proto(resp)
poplib.error_proto: b"-ERR Invalid message number: b'1'"发布于 2016-11-03 07:28:42
您正在尝试将str作为消息号传递。更改以下行
msg_num, _ = msg.split()至
msg_num = int(msg.split()[0])https://stackoverflow.com/questions/40395798
复制相似问题