This is the code
import poplib
from email import parser
pop_conn = poplib.POP3_SSL('pop.gmail.com')
pop_conn.user('user@gmail.com')
pop_conn.pass_('password')
messages = [pop_conn.retr(i) for i in range(1, len(pop_conn.list()[1]) + 1)]
messages = ["\n".join(mssg[1]) for mssg in messages]
messages = [parser.Parser().parsestr(mssg) for mssg in messages]
for message in messages:
print(message)
When it gets to the 8th line ( messages = ["\\n".join(mssg[1]) for mssg in messages]
)
It says this:
TypeError: sequence item 0: expected str instance, bytes found
Does anyone know what i'm doing wrong?
使用bytes.decode
将bytes对象转换为字符串:
messages = ["\n".join(m.decode() for m in mssg[1]) for mssg in messages]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.