This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: UnicodeEncodeError onsmtplib.login(MAIL_USER, MAIL_PASSWORD)
Type: crash Stage: resolved
Components: Library (Lib) Versions: Python 3.5
Status: closed Resolution: duplicate
Dependencies: Superseder: smtplib doesn't handle unicode passwords
View: 29750
Assigned To: Nosy List: JustAnother1, giampaolo.rodola, r.david.murray, taleinat
Priority: normal Keywords:

Created on 2018-06-02 22:40 by JustAnother1, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 8938 open Windson Yang, 2018-08-26 07:29
Messages (5)
msg318517 - (view) Author: Lars Pötter (JustAnother1) Date: 2018-06-02 22:40
if the password contains non ascii characters then the login fails:
>>> smtObj.login(MAIL_USER, MAIL_PASSWORD) 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.5/", line 720, in login
  File "/usr/lib/python3.5/", line 637, in auth
    authobject(challenge).encode('ascii'), eol='')
  File "/usr/lib/python3.5/", line 650, in auth_cram_md5
    self.password.encode('ascii'), challenge, 'md5').hexdigest()
UnicodeEncodeError: 'ascii' codec can't encode character '<removed>' in position <removed>: ordinal not in range(128)
msg319205 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2018-06-10 08:29
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.
msg319212 - (view) Author: Lars Pötter (JustAnother1) Date: 2018-06-10 12:04
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?
msg319216 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2018-06-10 12:34
We definitely need an expert to weigh in on this.
msg319221 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2018-06-10 14:14
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.
Date User Action Args
2022-04-11 14:59:01adminsetgithub: 77922
2018-08-26 07:29:09Windson Yangsetpull_requests: + pull_request8410
2018-06-10 14:14:35r.david.murraysetstatus: open -> closed

superseder: smtplib doesn't handle unicode passwords

nosy: + r.david.murray
messages: + msg319221
resolution: duplicate
stage: resolved
2018-06-10 12:34:03taleinatsetnosy: + giampaolo.rodola
messages: + msg319216
2018-06-10 12:04:23JustAnother1setmessages: + msg319212
2018-06-10 08:29:48taleinatsetnosy: + taleinat
messages: + msg319205
2018-06-02 22:40:36JustAnother1create