472,354 Members | 1,929 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,354 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 3875
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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made but the http to https rule only works for...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...

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.