469,270 Members | 1,633 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,270 developers. It's quick & easy.

urlib.quote gives KeyError in Python 2.4.4 but workin 2.3.5

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
3 3703
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
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
"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.

Similar topics

reply views Thread by Norman Shelley | last post: by
5 posts views Thread by Alex Hunsley | last post: by
1 post views Thread by | last post: by
3 posts views Thread by Rune Strand | last post: by
7 posts views Thread by Tommy.Ryding | last post: by
6 posts views Thread by vipulagarwal.in | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.