D
D
Dmitry Klepcha2014-08-16 12:44:53
Python
Dmitry Klepcha, 2014-08-16 12:44:53

How to fix email encoding in Python?

Good day everyone. There is a problem with encodings. Here is the code pastebin.com/2JbitPVR, here is the output pastebin.com/62uiemJR. On Yandex itself, all letters are readable. How to properly process message encoding?
Re- uploaded code pastebin.com/BRBaUifB, output pastebin.com/iPq349sn

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim, 2014-08-17
@1kachan

try adding:
# -*- coding: utf-8 -*-
to the beginning of the script

C
crazylh, 2014-08-17
@crazylh

The text of the letter must be encoded in latin-1 like this:

response = server.fetch(message_id, ['RFC822'])
messageString = response[0].get('RFC822')
msg = email.message_from_string(messageString.encode('latin1'))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question