E
E
Evgeny Dolbanovsky2019-05-11 15:43:26
Python
Evgeny Dolbanovsky, 2019-05-11 15:43:26

Why does Python + imap give an error "'ascii' codec can't encode characters" when searching for an email subject in Russian?

Code with Russian text gives you an error: UnicodeEncodeError: 'ascii' codec can't encode characters in position 41-44: ordinal not in range(128)

ttsender = 'тест вложения'
result, data = mail.uid('search', None, '(FROM "%s" HEADER Subject "%s" UNSEEN)' % (sender, ttsender))

A similar code with only the English text of the subject line works fine and looks for everything as it should.
Googled all day long, encode() decode() doesn't help at all
Comrades what is it???

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2019-05-11
@Rsa97

Because according to the standard, letter headers (From, To, Subject, ...) can only contain printable characters from ASCII-128, that is, with codes from 0x20 to 0x7F.

D
Dimonchik, 2019-05-11
@dimonchik2013

in programming there are no languages
, there are encodings

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question