Problem: neither urllib2.quote nor urllib.quote encode the unicodestrings arguments

Discussion in 'Python' started by Valery Khamenya, Oct 3, 2008.

  1. 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.
    thanks in advance,
    best regards
    --
    Valery
     
    Valery Khamenya, Oct 3, 2008
    #1
    1. Advertising

  2. Re: Problem: neither urllib2.quote nor urllib.quote encode the unicode strings arguments

    In message <>, Valery
    Khamenya wrote:

    > things like urllib.quote(u"пиво Müller ") fail with error message:
    > <type 'exceptions.KeyError'>: u'\u043f'


    Did you try encoding it as UTF-8 first?
     
    Lawrence D'Oliveiro, Oct 4, 2008
    #2
    1. Advertising

  3. Valery Khamenya

    Rou Bao Guest

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

    On 10ÔÂ4ÈÕ, ÉÏÎç5ʱ38·Ö, "Valery Khamenya" <> 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.
    > thanks in advance,
    > best regards
    > --
    > Valery


    don't unicode the str, just urllib.quote("§á§Ú§Ó§à M¨¹ller ")
     
    Rou Bao, Oct 5, 2008
    #3
  4. Valery Khamenya

    Miki Guest

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

    Hello,

    > 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

    ..

    n = u"§á§Ú§Ó§à M¨¹ller "
    print urllib.quote(n.encode("utf-8")) -> %D0%BF%D0%B8%D0%B2%D0%BE%20M
    %C3%BCller

    HTH,
    --
    Miki <>
    http://pythonwise.blogspot.com
     
    Miki, Oct 5, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Luigi Donatello Asero

    A text which neither gets very narrow nor disappears

    Luigi Donatello Asero, Oct 3, 2005, in forum: HTML
    Replies:
    21
    Views:
    896
    Jonathan N. Little
    Jan 6, 2006
  2. -berlin.de
    Replies:
    7
    Views:
    1,094
    Richard Tobin
    Feb 26, 2007
  3. pabbu
    Replies:
    8
    Views:
    757
    Marc Boyer
    Nov 7, 2005
  4. Jerry Hill
    Replies:
    0
    Views:
    496
    Jerry Hill
    Oct 4, 2008
  5. steveski
    Replies:
    3
    Views:
    818
    Ken Cox [Microsoft MVP]
    Jan 26, 2005
Loading...

Share This Page