473,396 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 3955
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Norman Shelley | last post by:
Is there a way to get at the object one is trying to access with a key to list out all the possible keys? See the except clause below. #!/usr/bin/env python2.2 from inspect import * import sys...
5
by: Alex Hunsley | last post by:
I'm using urllib to post data to a web form by issuing a command similar to this: filename, headers = urllib.urlretrieve("http://www.thewebsitenamehere.com/servlet/com.blah.bloo.XmlFeed",...
1
by: | last post by:
Hello. Maybe someone will help me with this KeyError: ............................. Traceback (most recent call last): File "C:\Python\tabla.py", line 929, in -toplevel- tablesDirectory =...
9
by: wordsender | last post by:
Hey guys, I can't figure this one out, why is this simple script giving me problems? logfile=file(r'test.txt','w') logfile.write('datetime') test=logfile.readlines() When I run it I get...
3
by: Rune Strand | last post by:
I'm experiencing strange errors both with pickle and cPickle in the below code: import cPickle as pickle #import pickle from string import ascii_uppercase from string import ascii_lowercase...
7
by: Tommy.Ryding | last post by:
Hi All I have a problem with extentions of Python. Background: I'm workin within a large industrial control system and I have created a Port for VxWorks. In the system we have different...
6
by: vipulagarwal.in | last post by:
hi i hav written a code in python to send an SMS from a nokia 3310 connected to my PC... i wanted to receive a msg on my PC. In order to do so, the PC must know when it has to read data frm the...
3
by: splintercell | last post by:
well i got this code from java.sun.com and tried modiifying it in all the possible ways,but to no good.. stil its not workin..pleas help me out and try postin good workinw web cralwer if u have.....
3
by: Valery Khamenya | last post by:
Hi all things like urllib.quote(u"пиво Müller ") fail with error message: <type 'exceptions.KeyError'>: u'\u043f' Similarly with urllib2. Anyone got a hint?? I need it to form the URI...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.