Re: urllib.urlencode wrongly encoding ± character

Serge Orlov Serge.Orlov at gmail.com
Wed Apr 5 22:57:06 EDT 2006


sleytr at gmail.com wrote:
> Hi,  I'm trying to make a gui for a web service. Site using ±
> character in value of some fields. But I can't encode this character
> properly.
>
>
> >>> data = {'key':'±'}
> >>> urllib.urlencode(data)
> 'key=%C2%B1'
>
> but it should be only %B1 not %C2%B1.

It should be %C2%B1, because de-facto urls are encoded as utf-8. I've
just tried entering ± into four input field: firefox 1.5 search
toolbar, www.google.com search in firefox 1.5, google toolbar in IE 6,
www.google.com search in IE 6. Everywhere ± is encoded as %C2%B1. In
older browsers YMMV.

> where is this %C2 coming from?

Your console must be utf-8.
>>> u'±'.encode('utf-8')
'\xc2\xb1'




More information about the Python-list mailing list