#26971: UnicodeDecodeError with non-ASCII string in quoted URL -------------------------+------------------------------------------------- Reporter: Oleg78 | Owner: nobody Type: Bug | Status: new Component: HTTP | Version: 1.8 handling | Keywords: UnicodeDecodeError UTF-8 Severity: Normal | windows-1251 URL wsgi Triage Stage: | Has patch: 0 Unreviewed | Easy pickings: 0 | UI/UX: 0 -------------------------+------------------------------------------------- Django raises UnicodeDecodeError if there are non UTF-8 characters in the url.
[https://github.com/django/django/blob/master/django/core/handlers/wsgi.py#L190]: {{{ return path_info.decode(UTF_8) }}} It doesn't work if the parameter in the URL is not in UTF-8 {{{/tag/%E7%E0%EA%EB%E0%E4%EA%E0/}}}: {{{ GET /tag/%E7%E0%EA%EB%E0%E4%EA%E0/ => generated 0 bytes in 1 msecs (HTTP/1.1 400) 1 headers in 68 bytes (1 switches on core 0) Bad Request (UnicodeDecodeError) Traceback (most recent call last): File "/home/ubuntu/django/lib/python3.4/site- packages/django/core/handlers/wsgi.py", line 167, in __call__ request = self.request_class(environ) File "/home/ubuntu/django/lib/python3.4/site- packages/django/core/handlers/wsgi.py", line 80, in __init__ path_info = get_path_info(environ) File "/home/ubuntu/django/lib/python3.4/site- packages/django/core/handlers/wsgi.py", line 197, in get_path_info return path_info.decode(UTF_8) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe7 in position 5: invalid continuation byte }}} With utf url-quoted parameter {{{/tag/%D0%B7%D0%B0%D0%BA%D0%BB%D0%B0%D0%B4%D0%BA%D0%B0}}} there is no errors, but the old site has used windows-1251 encoding and I need to support old links. So I use this dirty hack: {{{#!python try: return path_info.decode(UTF_8) except: return path_info.decode(windows-1251) }}} The problem is only in wsgi handler, {{{manage.py runserver}}} handles non-utf urls without errors. -- Ticket URL: <https://code.djangoproject.com/ticket/26971> Django <https://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 unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/049.e4df2066e3618ff5298b9cd7362c7731%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.