我找到了一个代码here并为自己尝试了但是我一直收到一个我不知道如何解决的错误。错误是这样的:TypeError: initial_value must be str or None, not bytes
这是由msg = email.message_from_string(j)
我的问题是如何解决此错误?如果我需要将其更改为字符串,我该怎么做呢?我还是python的新手。
完整代码:
import poplib,email
pop3_host = 'pop.gmail.com'
pop3_user = 'my_email'
pop3_pass = 'my_password'
## connect to host using SSL
pop3_mail = poplib.POP3_SSL(pop3_host)
## print the response message from server
print (pop3_mail.getwelcome())
## send user
pop3_mail.user(pop3_user)
## send password
pop3_mail.pass_(pop3_pass)
## let's fetch mail
print ("\n\n===\nLatest Mail\n===\n\n")
numMessages = len(pop3_mail.list())
for i in str(numMessages):
for j in pop3_mail.retr(i)[1]:
msg = email.message_from_string(j) # new statement
print(msg.get_payload())