if the password contains non ascii characters then the login fails: >>> smtObj.login(MAIL_USER, MAIL_PASSWORD) Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3.5/smtplib.py", line 720, in login initial_response_ok=initial_response_ok) File "/usr/lib/python3.5/smtplib.py", line 637, in auth authobject(challenge).encode('ascii'), eol='') File "/usr/lib/python3.5/smtplib.py", line 650, in auth_cram_md5 self.password.encode('ascii'), challenge, 'md5').hexdigest() UnicodeEncodeError: 'ascii' codec can't encode character '' in position : ordinal not in range(128)
Is this a bug? Are passwords containing non-ASCII characters supposed to be supported? If so, which encoding should be assumed for the password? Since it needs to be base64-encoded, it must be encoded into bytes.
I wanted to login to an existing account so the password works OK in Thunderbird. Here in Germany it is recommended for safe passwords to use the German umlauts(ßÄÖÜäöü). So code page 437 vs 850 or UTF-8 ? If I could pass in the bytes then I could figure out the correct encoding myself.(Try and error) I suppose that in other regions people want to use other encodings. And as long as the encoding is the same when setting the password and transmitting the password then everything is fine, right?
Duplicate of #29750. TLDR: smtplib needs to be fixed to handle binary passwords, and probably to use utf-8 as the default encoding for unicode passwords.