views:

311

answers:

1

Hi there im kinda stucked with the url encoding between python and javascript, i hope you can help me out :S

Javascript:

encodeURIComponent('lôl');
-> "l%C3%B4l"

Python:

import urllib
test = container.REQUEST.form.get('test')
print test
print urllib.unquote(test)
-> "lÃŽl"
-> "lÃŽl"

Javascript encodes "lôl" twice however python does that once with it, i dunno how to escape from there because i receive anyway throgh the Prototype HTTP GET request "l%C3%B4l" instead of "l%F4l"

Best Regards Bny

**edit its on a zope webserver

+1  A: 

zope already url-decodes it - issue is that you're getting a utf-8 bytestring and printing it on a non-utf-8 terminal. Try decoding the string.

x = 'l\xc3\xb4l'
unicode_x = x.decode('utf-8')
print unicode_x
nosklo
Thanks alot that worked well but how can i merge now that unicode string (with especially chars) with my normal string? i receive always and "UnicodeEncodeError" :S
Bny
@Bny: decode your normal string too. Use only unicode all over the place. If you're defining the string on the code, use `u'foo'` literal syntax.
nosklo