html POST in python

John J. Lee jjl at pobox.com
Tue Jun 29 15:45:43 EDT 2004


simoninusa2001 at yahoo.co.uk (simo) writes:

> # create array of name/value pairs
> self.params = urllib.urlencode({'user': 'fred', 'password': 'hax0r5'})
> 
> # send http-post
> request = urllib.urlopen("http://www.domain.com/login.cgi", params)
> 
> # read back each line of reply
> line = request.readline()

That's a generic POST, but there's a bit more to it for file upload,
which is what the OP seemed to want.

If you don't want the HTML parsing that my rather heavy ClientForm
library does (heavyweight for the job it does, anyway), there are
functions lying around for doing file upload in traditional procedural
style.  Can't remember where, but no doubt they're Google-able for.


John



More information about the Python-list mailing list