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 :
`[Mon Feb 06 13:50:53.062546 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] mod_wsgi (pid=17650): Exception occurred processing WSGI script '/home/projet/my_client/my_project/pyr-my_project/lib/python2.7/site-packages/my_project/integr_wsgi.py'.
[Mon Feb 06 13:50:53.062610 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] Traceback (most recent call last):
[Mon Feb 06 13:50:53.062634 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] File "/home/projet/my_client/my_project/pyr-my_project/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 170, in call
[Mon Feb 06 13:50:53.062763 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] response = self.get_response(request)
[Mon Feb 06 13:50:53.062783 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] File "/home/projet/my_client/my_project/pyr-my_project/lib/python2.7/site-packages/django/core/handlers/base.py", line 124, in get_response
[Mon Feb 06 13:50:53.062893 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] response = self._middleware_chain(request)
[Mon Feb 06 13:50:53.062912 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] File "/home/projet/my_client/my_project/pyr-my_project/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner
[Mon Feb 06 13:50:53.063000 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] response = response_for_exception(request, exc)
[Mon Feb 06 13:50:53.063018 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] File "/home/projet/my_client/my_project/pyr-my_project/lib/python2.7/site-packages/django/core/handlers/exception.py", line 86, in response_for_exception
[Mon Feb 06 13:50:53.063043 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
[Mon Feb 06 13:50:53.063057 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] File "/home/projet/my_client/my_project/pyr-my_project/lib/python2.7/site-packages/django/core/handlers/exception.py", line 124, in handle_uncaught_exception
[Mon Feb 06 13:50:53.063077 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] extra={'status_code': 500, 'request': request},
[Mon Feb 06 13:50:53.063090 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] File "/usr/lib64/python2.7/logging/init.py", line 1175, in error
[Mon Feb 06 13:50:53.063499 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] self._log(ERROR, msg, args, kwargs)
[Mon Feb 06 13:50:53.063519 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] File "/usr/lib64/python2.7/logging/init.py", line 1268, in _log
[Mon Feb 06 13:50:53.063542 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] self.handle(record)
[Mon Feb 06 13:50:53.063555 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] File "/usr/lib64/python2.7/logging/init.py", line 1278, in handle
[Mon Feb 06 13:50:53.063572 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] self.callHandlers(record)
[Mon Feb 06 13:50:53.063584 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] File "/usr/lib64/python2.7/logging/init.py", line 1318, in callHandlers
[Mon Feb 06 13:50:53.063622 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] hdlr.handle(record)
[Mon Feb 06 13:50:53.063637 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] File "/usr/lib64/python2.7/logging/init.py", line 749, in handle
[Mon Feb 06 13:50:53.063655 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] self.emit(record)
[Mon Feb 06 13:50:53.063667 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] File "/home/projet/my_client/my_project/pyr-my_project/lib/python2.7/site-packages/django/utils/log.py", line 121, in emit
[Mon Feb 06 13:50:53.063760 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] self.send_mail(subject, message, fail_silently=True, html_message=html_message)
[Mon Feb 06 13:50:53.063776 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] File "/home/projet/my_client/my_project/pyr-my_project/lib/python2.7/site-packages/django/utils/log.py", line 124, in send_mail
[Mon Feb 06 13:50:53.063799 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] mail.mail_admins(subject, message, *args, connection=self.connection(), kwargs)
[Mon Feb 06 13:50:53.063813 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] File "/home/projet/my_client/my_project/pyr-my_project/lib/python2.7/site-packages/django/core/mail/init.py", line 103, in mail_admins
[Mon Feb 06 13:50:53.063887 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] mail.send(fail_silently=fail_silently)
[Mon Feb 06 13:50:53.063903 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] File "/home/projet/my_client/my_project/pyr-my_project/lib/python2.7/site-packages/django/core/mail/message.py", line 342, in send
[Mon Feb 06 13:50:53.064068 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] return self.get_connection(fail_silently).send_messages([self])
[Mon Feb 06 13:50:53.064086 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] File "/home/projet/my_client/my_project/pyr-my_project/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 107, in send_messages
[Mon Feb 06 13:50:53.064181 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] sent = self._send(message)
[Mon Feb 06 13:50:53.064198 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] File "/home/projet/my_client/my_project/pyr-my_project/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 123, in _send
[Mon Feb 06 13:50:53.064221 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] self.connection.sendmail(from_email, recipients, message.as_bytes(linesep='
r
n'))
[Mon Feb 06 13:50:53.064235 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] File "/home/projet/my_client/my_project/pyr-my_project/lib/python2.7/site-packages/django/core/mail/message.py", line 180, in as_string
[Mon Feb 06 13:50:53.064254 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] g.flatten(self, unixfrom=unixfrom)
[Mon Feb 06 13:50:53.064266 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] File "/home/projet/my_client/my_project/pyr-my_project/lib/python2.7/site-packages/email/generator.py", line 84, in flatten
[Mon Feb 06 13:50:53.064426 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] self._write(msg)
[Mon Feb 06 13:50:53.064444 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] File "/home/projet/my_client/my_project/pyr-my_project/lib/python2.7/site-packages/email/generator.py", line 109, in _write
[Mon Feb 06 13:50:53.064467 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] self._dispatch(msg)
[Mon Feb 06 13:50:53.064479 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] File "/home/projet/my_client/my_project/pyr-my_project/lib/python2.7/site-packages/email/generator.py", line 135, in _dispatch
[Mon Feb 06 13:50:53.064497 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] meth(msg)
[Mon Feb 06 13:50:53.064511 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] File "/home/projet/my_client/my_project/pyr-my_project/lib/python2.7/site-packages/email/generator.py", line 178, in _handle_text
[Mon Feb 06 13:50:53.064537 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] self._fp.write(payload)
[Mon Feb 06 13:50:53.064569 2017] [:error] [pid 17650] [remote 192.168.34.196:61833] 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?