beating a dead horse: automated form submission

Peter Hansen peter at engcorp.com
Sun Jan 26 13:21:21 EST 2003


Whit Whitfield wrote:
> 
> Well I'm tinkering with the snippet from the FAQ and trying it out on
> www.musi-cal.com'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("www.musi-cal.com:80")
conn.request("POST", "/cgi-bin/query", params, headers)
response = conn.getresponse()
print response.status, response.reason
data = response.read()
conn.close()




More information about the Python-list mailing list