urllib.urlencode wrongly encoding ő character

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • M Kusanagi
    New Member
    • Mar 2011
    • 1

    urllib.urlencode wrongly encoding ő character

    Hello
    I try post 'paste' to
    http://1337.pastebay.c om/
    using python urlencode,
    when i check headers with Firefox liveHttpHeaders , the
    ő character encoded to
    %26%23337%3B

    but when try in python:
    In [28]: urlencode({'cod e2':u'ő'.encode ('iso-8859-1')})
    Out[28]: 'code2=%C5%91'

    In [29]: urlencode({'cod e2':u'ő'.encode ('utf8')})
    Out[29]: 'code2=%C3%85%C 2%91'

    I cant understand why FF, encode differ from python.

    When i send post form in python, characters became weird on given html page...

    In [32]: o = urllib2.build_o pener()

    In [33]: o.open('http://1337.pastebay.c om/pastebay.php',' parent_pid=1163 99&format=vb&co de2=%C5%91&prot ected=&poster=& paste=Send&expi ry=m&pam=')
    Out[33]: <addinfourl at 47655680 whose fp = <socket._fileob ject object at 0x2d635d0>>

    In [34]: _.url
    Out[34]: 'http://1337.pastebay.c om/116408'

    as you see on url above, i got: ' Å‘ '
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    The first thing to check is the encoding used by Firefox/pastebay.com. If it is different from 'iso-8859-1' or 'utf8' that would explain the difference.

    Comment

    Working...