Convert dictionary to HTTP POST

Steve Holden steve at
Fri Mar 3 15:09:20 CET 2006

[copied to list]

Laszlo Zsolt Nagy wrote:
>> See urllib.urlencode(). No idea why they don't include it in urllib2 
>> as well, but there you go.
>> >>> from urllib import urlencode
>> >>> urlencode({'a':'& "Simple string"', 'b': '<>!@#$%^&*()_+='})
>> 'a=%26+%22Simple+string%22&b=%3C%3E%21%40%23%24%25%5E%26%2A%28%29_%2B%3D'
>> >>>
> Hmm. urlencode is using quote_plus internally. Looks like there is no 
> difference in the encoding of the apostrophe.
> I tried to create a very basic form and realized that the problem is NOT 
> with the quoting.
> I'm writting a program that puts orders into a wholesaler's database.
> They do not have a programatic interface, so I have to login and post 
> forms using a program.
> There are some fields that I must not change, so I have to read the 
> value from the HTML source and then post it back.
> Here is the problem:
> <html>
> <body>
> <form method="POST">
>  <input name="name" value="Bessy's cat">
>  <input type="submit">
> </form>
> </body>
> </html>
> The values of some inputs are encoded using html entities.
> How can I decode a string like "Bessy's cat"  in "Bessy's cat"?
> Thanks,
>   Laszlo
Well I don't understand what's encoding the apostrophe as an encoded 
entity anyway. That's only supposed to be done for HTML content, not 
form content. You will find that the string "Bessy's cat" works just as 

That should actually be transmitted as "Bessy%39s cat" when sent to the 

How about an RE that turned all &#DD; into %DD ?

Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd       
Love me, love my blog

More information about the Python-list mailing list