By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,100 Members | 2,979 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,100 IT Pros & Developers. It's quick & easy.

urlib.quote gives KeyError in Python 2.4.4 but workin 2.3.5

P: n/a
urllib.quote chokes on unicode in 2.4.4.
>>print sys.version
2.4.4 (#1, Oct 18 2006, 10:34:39)
[GCC 4.0.1 (Apple Computer, Inc. build 5341)]
>>urllib.quote(u"\xe9")
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File
"/Library/Frameworks/Python.framework/Versions/2.4//lib/python2.4/urllib.py",
line 1117, in quote
res = map(safe_map.__getitem__, s)
KeyError: u'\xe9'

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'

Is this a known bug?

What's the workaround?

Thanks,
nyenyec

Jan 7 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
encode seems to solve my problem:
>>urllib.quote(u'\xe9'.encode('utf-8'))
'%C3%A9'

Cheers,
nyenyec

nyenyec wrote:
urllib.quote chokes on unicode in 2.4.4.
>print sys.version
2.4.4 (#1, Oct 18 2006, 10:34:39)
[GCC 4.0.1 (Apple Computer, Inc. build 5341)]
>urllib.quote(u"\xe9")
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File
"/Library/Frameworks/Python.framework/Versions/2.4//lib/python2.4/urllib.py",
line 1117, in quote
res = map(safe_map.__getitem__, s)
KeyError: u'\xe9'

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'

Is this a known bug?

What's the workaround?

Thanks,
nyenyec
Jan 7 '07 #2

P: n/a
On 7 ene, 15:48, "nyenyec" <nyen...@gmail.comwrote:
urllib.quote chokes on unicode in 2.4.4.
>>urllib.quote(u"\xe9")
KeyError: u'\xe9'

but it seems to work in Python 2.3.5

Is this a known bug?
See some recent posts about "urllib.unquote and unicode"

--
Gabriel Genellina

Jan 7 '07 #3

P: n/a
"nyenyec" <ny*****@gmail.comwrote:
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.
Jan 7 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.