Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Problem: neither urllib2.quote nor urllib.quote encode theunicode strings arguments

Reply
Thread Tools

Re: Problem: neither urllib2.quote nor urllib.quote encode theunicode strings arguments

 
 
Jerry Hill
Guest
Posts: n/a
 
      10-03-2008
On Fri, Oct 3, 2008 at 5:38 PM, Valery Khamenya <(E-Mail Removed)> wrote:
> 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 containing non-ascii chars.


Do you know what, exactly, you'd like the result to be? The encoding
of unicode characters into URIs is not well defined. My understanding
is that the most common case is to percent-encode UTF-8, like this:

>>> u = u"Müller"
>>> import urllib
>>> urllib.quote(u.encode('utf8'))

'M%C3%BCller'

If you need to, you can encode your unicode string differently, like this:

>>> urllib.quote(u.encode('latin-1'))

'M%FCller'

--
Jerry
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem: neither urllib2.quote nor urllib.quote encode the unicodestrings arguments Valery Khamenya Python 3 10-05-2008 10:16 AM
XPath Problem: Select all childnodes, that names are neither "name1" nor "name2" adurth@cs.tu-berlin.de XML 7 02-26-2007 02:03 PM
A text which neither gets very narrow nor disappears Luigi Donatello Asero HTML 21 01-06-2006 11:32 PM
c is a low-level language or neither low level nor high level language pabbu C Programming 8 11-07-2005 03:05 PM
Neither Han nor Greedo will shoot first Mark W DVD Video 6 12-05-2003 07:45 AM



Advertisments