urlib.quote gives KeyError in Python 2.4.4 but workin 2.3.5

Duncan Booth duncan.booth at invalid.invalid
Sun Jan 7 14:34:04 EST 2007


"nyenyec" <nyenyec at gmail.com> wrote:

> but it seems to work in Python 2.3.5
> 
> Python 2.3.5 (#1, Aug 19 2006, 21:31:42)
> [GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import sys, urllib
>>>> print sys.version
> 2.3.5 (#1, Aug 19 2006, 21:31:42)
> [GCC 4.0.1 (Apple Computer, Inc. build 5363)]
>>>> urllib.quote(u'\xe9')
> '%E9'

'seems to' is correct: it should *probably* have given you '%C3%E9'.

> 
> Is this a known bug?
> 
> What's the workaround?

UTF-8 encode the url before quoting it.

*Some* web servers may not expect utf-8 encoding. utf-8 is the recommended 
encoding, but unfortunately it isn't actually required, so a few (mostly 
old) servers may expect something else. If so, use the appropriate encoding 
for the server.



More information about the Python-list mailing list