Opened 15 years ago

Closed 15 years ago

#11921 closed (duplicate)

UnicodeEncodeError when using redirect_to with non-ascii keywords

Reported by: Ian Lewis Owned by: nobody
Component: Uncategorized Version: 1.1
Severity: 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

I have a urls.py that looks something like

from django.conf.urls.defaults import *

urlpatterns = patterns('django.views.generic.simple',
    url(r'^jp/(?P<tag_name>.+)\;', 'redirect_to', {'url': '/jp/tag/%(tag_name)s'}),
)

But if the tag_name is non-ascii then I get the following error:

Traceback (most recent call last):

 File "/home/ianlewis/.virtualenvs/test/lib/python2.5/site-packages/django/core/handlers/base.py", line 92, in get_response
   response = callback(request, *callback_args, **callback_kwargs)

 File "/home/ianlewis/.virtualenvs/test/lib/python2.5/site-packages/django/views/generic/simple.py", line 39, in redirect_to
   return klass(url % kwargs)

 File "/home/ianlewis/.virtualenvs/test/lib/python2.5/site-packages/django/http/__init__.py", line 414, in __init__
   self['Location'] = redirect_to

 File "/home/ianlewis/.virtualenvs/test/lib/python2.5/site-packages/django/http/__init__.py", line 320, in __setitem__
   header, value = self._convert_to_ascii(header, value)

 File "/home/ianlewis/.virtualenvs/test/lib/python2.5/site-packages/django/http/__init__.py", line 309, in _convert_to_ascii
   value = value.encode('us-ascii')

UnicodeEncodeError: 'ascii' codec can't encode characters in position 8-11: ordinal not in range(128), HTTP response headers must be in US-ASCII format

This may be related to #11522 but as I'm not redirecting to a relative url I wanted to make sure this case was also covered.

Change History (1)

comment:1 by Karen Tracey, 15 years ago

Resolution: duplicate
Status: newclosed

Dupe of #11522. I changed the summary there to remove the overly specific problem description; the discussion already made it clear the root of the problem is the location header is not consistently being url-encoded before being converted to ASCII.

Note: See TracTickets for help on using tickets.
Back to Top