Answer the question
In order to leave comments, you need to log in
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))
Answer the question
In order to leave comments, you need to log in
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.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question