urllib.urlencode wrongly encoding ± character
Fredrik Lundh
fredrik at pythonware.com
Thu Apr 6 05:48:25 EDT 2006
sleytr at gmail.com wrote:
> I think there should be way to encode ± to %B1 on any platform/locale
> combination. While searching for a real solution, I'm going to add a
> search&destroy filter for %C2 on urlencoded dictionary as a workaround.
> Because my queries are constant and %C2 is the only problem for now.
I'm obviously missing some context here, but "encoding ± to %B1 on any
platform" is exactly what urlencode does:
>>> import urllib
>>> urllib.urlencode([("key", chr(0xb1))])
'key=%B1'
(however, if you pass in unicode values with non-ascii characters, url-
encode will give you an error).
are you sure the conversion to UTF-8 isn't happening *before* you pass
your data to urlencode ? what does
print "1", repr(data)
print "2", repr(urllib.urlencode(data))
print for the kind of data you're encoding ?
</F>
More information about the Python-list
mailing list