beating a dead horse: automated form submission

Whit Whitfield whit at shaftnet.org
Sun Jan 26 18:38:34 CET 2003


Peter Hansen <peter at engcorp.com> wrote in message
news:<3E32EFD8.D00D4656 at engcorp.com>...
> To help you further, I'd have to see what you've been trying.  Can you
> not post a snippet or two of your code for us to review?

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:


#!/usr/local/bin/python

import httplib, sys, time

### build the query string
qs = "First=Josephine&amp;MI=Q&amp;Last=Public"
### connect and send the server a path
httpobj = httplib.HTTP('www.musi-cal.com', 80)
httpobj.putrequest('POST', '/cgi-bin/query')
### now generate the rest of the HTTP headers...
httpobj.putheader('Accept', '*/*')
httpobj.putheader('Connection', 'Keep-Alive')
httpobj.putheader('Content-type', 'application/x-www-form-urlencoded')
httpobj.putheader('Content-length', '%d' % len(qs))
httpobj.endheaders()
httpobj.send(qs)
### find out what the server said in response...
reply, msg, hdrs = httpobj.getreply()
if reply != 200:
    sys.stdout.write(httpobj.getfile().read())

... When I tried this it crashed WinPython :)

Thanks for any help!  -whit




More information about the Python-list mailing list