3

In process of coding email bot which reads and saves all attachments I have encountered with problem of reading attachments' filenames. They come in format of encoded2 string and are often in Russian( There are no problems with English names). How can I decode this format into Russian text, and what is this format? All my attempts were fruitless. If someone knows an explicit article please give a link. Would be greatful.

encoded = 'YmFzZTY0IGVuY29kZWQgc3RyaW5n'
encoded2 = '0J/QvtC00LPQvtGC0L7QstC60LAg0Log0JzQptCa0J4gMTDQuDIg0LHQu9C+0Log0L/RgNC+0LPRgNCw0LzQvNC40YDQvtCy0LDQvdC40Y8ucGRm'
data = base64.b64decode(encoded)
data2 = base64.b64decode(encoded2)
print(data2)#prints \xd0 .....
print(data) #prints b"base64 encoded string"
message = data2.decode("cp1251")
print(message)# outputs strange symbols РџРѕРґРіРѕ .....```


1 Answer 1

1

Use utf-8 instead of cp1251:

message = data2.decode("utf-8")

Output:

Подготовка к МЦКО 10и2 блок программирования.pdf
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.