beating a dead horse: automated form submission

Peter Hansen peter at
Sun Jan 26 19:21:21 CET 2003

Whit Whitfield wrote:
> Well I'm tinkering with the snippet from the FAQ and trying it out on
>'s little query page.  Here's the code:
> ### build the query string
> qs = "First=Josephine&MI=Q&Last=Public"

You shouldn't be using & here... that's only for XML
and HTML and such, not for query strings.  Query strings
use & itself to separate the key/value pairs from each other.

Not sure what else might be going wrong... why not try
the example from the documentation on httplib?

import httplib, urllib

fields = { "First": "Josephine", "MI": "Q", "Last": "Public" }
params = urllib.urlencode(fields)
headers = {"Content-type": "application/x-www-form-urlencoded",
               "Accept": "text/plain"}

conn = httplib.HTTPConnection("")
conn.request("POST", "/cgi-bin/query", params, headers)
response = conn.getresponse()
print response.status, response.reason
data =

More information about the Python-list mailing list