Convert dictionary to HTTP POST

Laszlo Zsolt Nagy gandalf at
Fri Mar 3 14:48:44 CET 2006

>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': '<>!@#$%^&*()_+='})
> >>>
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:

<form method="POST">
  <input name="name" value="Bessy&#39;s cat">
  <input type="submit">

The values of some inputs are encoded using html entities.
How can I decode a string like "Bessy&#39;s cat"  in "Bessy's cat"?



More information about the Python-list mailing list