By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,551 Members | 1,159 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,551 IT Pros & Developers. It's quick & easy.

urllib.urlencode wrongly encoding ő character

P: 1
Hello
I try post 'paste' to
http://1337.pastebay.com/
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({'code2':u'ő'.encode('iso-8859-1')})
Out[28]: 'code2=%C5%91'

In [29]: urlencode({'code2':u'ő'.encode('utf8')})
Out[29]: 'code2=%C3%85%C2%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_opener()

In [33]: o.open('http://1337.pastebay.com/pastebay.php','parent_pid=116399&format=vb&code2=% C5%91&protected=&poster=&paste=Send&expiry=m&pam=' )
Out[33]: <addinfourl at 47655680 whose fp = <socket._fileobject object at 0x2d635d0>>

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

as you see on url above, i got: ' ő '
Mar 7 '11 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 621
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.
Mar 8 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.