Answer the question
In order to leave comments, you need to log in
Why is there an error when reading a letter from mail via IMAP?
All letters are read, but some give an error
Traceback (most recent call last):
File "C:\Users\admin\Desktop\mail.py", line 121, in <module>
if LastSubject != ReadingMail():
File "C:\Users\admin\Desktop\mail.py", line 50, in ReadingMail
body = payload.get_payload(decode=True).decode('UTF-8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd0 in position 0: invalid continuation byte
email_message = email.message_from_string(raw_email_string, policy=policy.default)
if email_message.is_multipart():
for payload in email_message.get_payload():
body = payload.get_payload(decode=True).decode('UTF-8')
#print(body)
else:
body = email_message.get_payload(decode=True).decode('UTF-8')
#print(body)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question