S
S
Sasha Filinsky2021-08-02 19:10:16
Python
Sasha Filinsky, 2021-08-02 19:10:16

I receive a letter using imaplib but returns not UTF-8 but UNICODE, how can I fix it?

I read a letter from the mail but instead of the usual UTF-8 comes UNICODE

raw_email_string = raw_email.decode()

    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')
    else:    
      body = email_message.get_payload(decode=True).decode('UTF-8')


Although all letters come in UTF-8, but the letter that is sent through my mail is written in unicode.
How to fix it?

In META, UTF-8 encoding

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
ky0, 2021-08-02
@ky0

UTF-8 is a subset (more precisely, a way of representing ) of Unicode. Organize your thoughts about this in your head.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question