On Wed, 2009-08-05 at 01:32 -0700, alecs wrote: > Sorry :( > > return HttpResponseRedirect(path) brings Internal Server Error: > > > cat /var/log/apache2/error.log [... snip ...]
I can't immediately see why Python's urljoin() function is trying to do encoding/decoding at the point this explodes, but clearly it isn't happy with non-ASCII str objects. We might have to work around that in Django. It seems it should be possible to reduce this to a fairly simple test case of just returning an HttpRedirect with a UTF-8 encoded string, although I don't have time to sit down and work out the details right at the moment and my trivial attempt worked without error, so there's something special going on. I'm prepared to say this might be a Django bug (it's a mini-bug that we're not working around Python being slightly awkward). Probably worth opening a ticket, if there isn't already one in this area. If you can find a simple case that reliably demonstrates the problem, that would be useful, too. I might have just made a silly error when trying to create a standalone just now, but I can't stop to spend any more time on it. > if I set return HttpResponseRedirect(path.encode('utf8')) then I'm > getting: [...] > > Traceback: > File "/usr/share/python-support/python-django/django/core/handlers/ > base.py" in get_response > 91. response = callback(request, *callback_args, > **callback_kwargs) > File "/usr/share/python-support/python-django/django/contrib/auth/ > decorators.py" in __call__ > 78. return self.view_func(request, *args, **kwargs) > File "/var/www/filez/filezupload/views.py" in send_file > 256. return HttpResponseRedirect(path.encode('utf8')) > > Exception Type: UnicodeDecodeError at /file/ > f5c27ee3982ebf701793038d22c72980d64793f566cb0ac10269ee0b > Exception Value: ('ascii', '/var/upload/alecs/\xd0\xa6\xd0\xb5\xd0\xbb > \xd0\xb5\xd0\xb2\xd1\x8b\xd0\xb5 \xd0\xbf\xd0\xbe\xd0\xba > \xd0\xb0\xd0\xb7\xd0\xb0\xd1\x82\xd0\xb5\xd0\xbb\xd0\xb8 > \xd0\xb4\xd0\xb5\xd1\x8f\xd1\x82\xd0\xb5\xd0\xbb\xd1\x8c\xd0\xbd > \xd0\xbe\xd1\x81\xd1\x82\xd0\xb8 \xd0\xbd\xd0\xb0 2008 \xd0\xb3\xd0\xbe > \xd0\xb4.jpg', 18, 19, 'ordinal not in range(128)') That suggests to me that "path" isn't a unicode string in the first place. You see that sort of error if you try to encode data that is in a str object -- i.e. it is already UTF-8 encoded. I would suggest trying passing in path.decode('utf-8') -- converting the string back into unicode. It's possible I missed an edge-case when fixing bug #10267, since the tests included there only check for unicode strings being used in the Location header (for the non-ASCII case). Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---