#9370: Non utf-8 DEFAULT_CHARSET causes UnicodeDecodeError when serving binary data through middleware -------------------------------------+-------------------------------------- Reporter: kikko | Owner: kkubasik Status: reopened | Milestone: 1.1 Component: Core framework | Version: 1.0 Resolution: | Keywords: Stage: Accepted | Has_patch: 0 Needs_docs: 0 | Needs_tests: 0 Needs_better_patch: 0 | -------------------------------------+-------------------------------------- Changes (by kmtracey):
* status: closed => reopened * resolution: worksforme => * summary: UnicodeDecodeError when serving binary static files through GZipMiddleWare => Non utf-8 DEFAULT_CHARSET causes UnicodeDecodeError when serving binary data through middleware Comment: The bit of info missing from the descriptions that is key to hitting the problem is to have DEFAULT_CHARSET set to something other than utf-8 in settings.py. That's how you reach this line in the traceback: {{{ #!python File "/home/niksite/lib/site-python/django/utils/encoding.py", line 119, in smart_str return s.decode('utf-8', errors).encode(encoding, errors) }}} I tried setting DEFAULT_CHARSET to 'latin1' (and adding the gzip middleware) for one of my projects that generates and serves .png files and sure enough starting hitting this traceback. It's not specific to django.views.static.serve, nor really the gzip middleware, it's anything that causes this routine: {{{ #!python def _get_content(self): if self.has_header('Content-Encoding'): return ''.join(self._container) return smart_str(''.join(self._container), self._charset) }}} in `django/http/__init__.py` to be called and take the path of calling `smart_str` with binary (and thus non-likely-to-be-successfully-decoded using utf-8) data and `self._charset` set to something other than utf-8. Given the constraints needed to recreate this, it may be appropriate to defer this past 1.1. But it's also pretty late here right now so perhaps there is some easy fix that escapes me at the moment, so I'll leave that decision to someone else. -- Ticket URL: <http://code.djangoproject.com/ticket/9370#comment:7> Django <http://code.djangoproject.com/> The Web framework for perfectionists with deadlines. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-updates?hl=en -~----------~----~----~----~------~----~------~--~---