views:

195

answers:

1

I'm trying to get a GET parameter value that looks like this: http://someurl/handler.json?&q=%E1%F8%E0%F1%F8%E9

The q parameter in this case is Hebrew. I'm trying to read the value using the following code:

request.GET.get("q", None)

I'm getting gybrish instead of the correct text. Any idea what's wrong here? Am I missing some setting?

+3  A: 

The query string is in ISO-8859-8, but Django's default encoding is UTF-8. You will have to change either DEFAULT_CHARSET or HttpRequest.encoding to ISO-8859-8 to get the correct Unicode data.

Lukáš Lalinský
Or, if you can, change your application to use the UTF-8 encoding throughout. Webapps that don't support Unicode are so last century.
bobince
UTF-8 != Unicode.
Daniel Roseman
True, but ISO-8859-8 doesn't cover whole Unicode, so you can't say you support Unicode is you support only a small subset of it (ISO-8859-8).
Lukáš Lalinský
Doing the following works:request.encoding = 'ISO-8859-8'x = unicode(request.GET.get("q", None))But how do I support the full range of unicode characters?Doing request.encoding = 'utf-8' does not solve the problem...
Eran Kampf
To get a full range of Unicode characters you need to change the input to UTF-8 (in this specific case it would be `q=%D7%91%D7%A8%D7%90%D7%A1%D7%A8%D7%99`). If it's from your website then it shouldn't be a problem, but if it's some external application, you need to change that application.
Lukáš Lalinský
Thanks. Actually that string is what FireFox generated when I wrote Hebrew on the address bar...
Eran Kampf
Curious, parameters typed into the address bar should usually be UTF-8. They are for me in Firefox, whether I type Hebrew or Latin-1 characters (ISO-8859-1 is my default charset). Anyhow, it's relatively unusual to be typing full URLs with their query-parameters...
bobince