#19802: HttpResponse.set_cookie doesn't handle unicode data -------------------------------+-------------------------------------- Reporter: django@… | Owner: nobody Type: Bug | Status: new Component: HTTP handling | Version: 1.5 Severity: Normal | Resolution: Keywords: cookie | Triage Stage: Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------+-------------------------------------- Changes (by semenov):
* status: closed => new * resolution: worksforme => * version: 1.4 => 1.5 * type: Uncategorized => Bug * cc: semenov@… (added) Comment: This is still broken in 1.5. To reproduce the bug, use the experiment file below: {{{#!python # Put this in a file called experiment19802.py and run it with: # django-admin.py runserver --settings=experiment19802 from django.conf.urls import patterns, url from django.http import HttpResponse DEBUG = True ROOT_URLCONF = 'experiment19802' SECRET_KEY = 'whatever' def view(request): res = HttpResponse('OK') res.set_cookie('test', request.GET.get('cookie', '')) return res urlpatterns = patterns('', url(r'.*', view), ) }}} and try to open: http://localhost:8000/?cookie=M%C3%BCller It will raise the exception: {{{ Traceback: File "/Users/semenov/work/xxx/venv/lib/python2.7/site- packages/django/core/handlers/base.py" in get_response 115. response = callback(request, *callback_args, **callback_kwargs) File "/Users/semenov/tmp/19802/experiment19802.py" in view 13. res.set_cookie('test', request.GET.get('cookie', '')) File "/Users/semenov/work/xxx/venv/lib/python2.7/site- packages/django/http/response.py" in set_cookie 157. self.cookies[key] = value File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/Cookie.py" in __setitem__ 591. rval, cval = self.value_encode(value) File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/Cookie.py" in value_encode 680. strval = str(val) Exception Type: UnicodeEncodeError at / Exception Value: 'ascii' codec can't encode character u'\xfc' in position 1: ordinal not in range(128) }}} -- Ticket URL: <https://code.djangoproject.com/ticket/19802#comment:2> 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/082.95f2486ad313068742f78cdb31b9bb98%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.