Hi, I use the authentication views from django.contrib.auth
to my urls.py, and get an unexpected error:
UnicodeEncodeError at /reset_password/
'ascii' codec can't encode character '\u2019' in position 554: ordinal not in range(128)
[...]
23. self.stream.write("%s\n" % msg_data)
This is surprising not just because my own code is not involved at all, but also because the message does not contain any obvious non-ASCII characters:
charset
'utf-8'
message
<django.core.mail.message.EmailMultiAlternatives object at 0x10aee1ad0>
msg
<django.core.mail.message.SafeMIMEText object at 0x10b1a3010>
msg_data
('Content-Type: text/plain; charset="utf-8"\n'
'MIME-Version: 1.0\n'
'Content-Transfer-Encoding: 8bit\n'
'Subject: Password reset on lms.django\n'
'From: webmaster@example.com\n'
'To: testuser@example.com\n'
'Date: Sat, 16 Mar 2024 09:44:44 -0000\n'
'Message-ID: \n'
' <171058228430.54720.6766115132057211548@55.78.168.192.in-addr.arpa>\n'
'\n'
'\n'
"You're receiving this email because you requested a password reset for your "
'user account at lms.django.\n'
'\n'
'Please go to the following page and choose a new password:\n'
'\n'
'http://lms.django/reset/Mg/c3z72k-86698338ef6ab788941bf61dd916e\n'
'\n'
'Your username, in case you’ve forgotten: testuser\n'
'\n'
'Thanks for using our site!\n'
'\n'
'The lms.django team\n'
'\n'
'\n')
self
<django.core.mail.backends.console.EmailBackend object at 0x10b249f10>
What could cause this error, why does Django not take its own DEFAULT_CHARSET
(utf-8) into account when writing the message, and what can be done to solve the issue? Thanks in advance for any suggestions!