Non-ascii chars in source code causing UnicodeEncodeError for default 500 error handler, resulting in non-descriptive traceback-only error page
|Reported by:||tt@…||Owned by:||nobody|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Project developed for pre-unicode django version, not utilizing i18n and using national chars in source with iso-8859-1 encoding.
Django configured for serving with DEFAULT_CHARSET and FILE_CHARSET set to "iso-8859-1".
Django upgraded to current SVN, and the mod_apache error handler appears, giving UnicodeEncodeError deep in Django.
Traceback (most recent call last): File "/usr/lib/python2.3/site-packages/django/core/servers/basehttp.py", line 279, in run self.finish_response() File "/usr/lib/python2.3/site-packages/django/core/servers/basehttp.py", line 317, in finish_response for data in self.result: File "/usr/lib/python2.3/site-packages/django/http/__init__.py", line 332, in next chunk = chunk.encode(self._charset) UnicodeEncodeError: 'latin-1' codec can't encode characters in position 5735-5737: ordinal not in range(256)
The core problem seems to be chars from the non-allowed range enter the unicode-only path for django, for example in the case of str model methods not returning unicode.
That is obviously a problem in itself, but should not trip Django up this badly.
Other examples have also beed observed, but all relate to database or form data being touched by non-unicode strings.
Catching UnicodeEncodeError and using replace mechanism at least enables developer to find offending chars and convert code to unicode.
I don't know if this patch does the right thing, but it gives a workable error message.
See attached patch for details.
Change History (7)
Changed 8 years ago by tt@…
comment:1 Changed 8 years ago by mtredinnick
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Resolution set to wontfix
- Status changed from new to closed
comment:2 Changed 8 years ago by mtredinnick
- Resolution wontfix deleted
- Status changed from closed to reopened
- Triage Stage changed from Unreviewed to Accepted