Opened 8 years ago
Closed 8 years ago
#27811 closed Bug (wontfix)
Avoid UnicodeEncodeError during generation of email with mail_admins logger
Reported by: | Antoine Humbert | Owned by: | |
---|---|---|---|
Component: | Error reporting | Version: | 1.10 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When using localization (USE_L10N = True), generated message for mails triggered by the mail_admins logger may contains some non-ascii characters depending on current locale.
This is the case for the display of server_time if current locale is french :
In django.views.debug.py, the TECHNICAL_500_TEXT_TEMPLATE contains
Server time: {{server_time|date:"r"}}
which results, for example, in the following unicode string, for a french locale :
lun, 6 Fév 2017 15:15:32 +0100
A solution would be to use a locale independant format (as suggested by the use_l10n=False defined in Context object created at ExceptionReporter.get_traceback_text), such as "c" format.
Change History (3)
comment:1 by , 8 years ago
comment:2 by , 8 years ago
The problem occurs in python 2.7.
The complete traceback is :
Traceback (most recent call last): File "site-packages/django/core/handlers/wsgi.py", line 170, in __call__ response = self.get_response(request) File "site-packages/django/core/handlers/base.py", line 124, in get_response response = self._middleware_chain(request) File "site-packages/django/core/handlers/exception.py", line 41, in inner response = response_for_exception(request, exc) File "site-packages/django/core/handlers/exception.py", line 86, in response_for_exception response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info()) File "site-packages/django/core/handlers/exception.py", line 124, in handle_uncaught_exception extra={'status_code': 500, 'request': request}, File "/usr/lib64/python2.7/logging/__init__.py", line 1175, in error self._log(ERROR, msg, args, **kwargs) File "/usr/lib64/python2.7/logging/__init__.py", line 1268, in _log self.handle(record) File "/usr/lib64/python2.7/logging/__init__.py", line 1278, in handle self.callHandlers(record) File "/usr/lib64/python2.7/logging/__init__.py", line 1318, in callHandlers hdlr.handle(record) File "/usr/lib64/python2.7/logging/__init__.py", line 749, in handle self.emit(record) File "site-packages/django/utils/log.py", line 121, in emit self.send_mail(subject, message, fail_silently=True, html_message=html_message) File "site-packages/django/utils/log.py", line 124, in send_mail mail.mail_admins(subject, message, *args, connection=self.connection(), **kwargs) File "site-packages/django/core/mail/__init__.py", line 103, in mail_admins mail.send(fail_silently=fail_silently) File "site-packages/django/core/mail/message.py", line 342, in send return self.get_connection(fail_silently).send_messages([self]) File "site-packages/django/core/mail/backends/smtp.py", line 107, in send_messages sent = self._send(message) File "site-packages/django/core/mail/backends/smtp.py", line 123, in _send self.connection.sendmail(from_email, recipients, message.as_bytes(linesep='\\r\\n')) [Mon Feb 06 13:50:53.064235 2017] File "site-packages/django/core/mail/message.py", line 180, in as_string g.flatten(self, unixfrom=unixfrom) File "site-packages/email/generator.py", line 84, in flatten self._write(msg) File "site-packages/email/generator.py", line 109, in _write self._dispatch(msg) File "site-packages/email/generator.py", line 135, in _dispatch meth(msg) File "site-packages/email/generator.py", line 178, in _handle_text self._fp.write(payload) UnicodeEncodeError: 'ascii' codec can't encode character u'\\xe9' in position 1124: ordinal not in range(128)`
comment:3 by , 8 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
The Django master branch no longer supports Python 2, so I think the time for fixing this (if it's a valid issue -- I haven't investigated the details) has passed.
Can you provide the complete traceback? Does it happen on Python 3?