html POST in python

John J. Lee jjl at
Mon Jun 28 16:44:10 CEST 2004

"Mark Light" <light at> writes:

> Hi I am trying to "post" a file to a webpage and save the output as a
> file. I have looked at
> which seems to have several suggestions - my problem is my lack of
> knowledge of html forms.
> The active part of the webpage form in question is below - how would I
> feed this information into one of the python scripts from the cookbook
> examples. Also would I need to do something about handling the result?
> I have a plain text file in a location say "c:\temp\file.cif"

Try ClientForm (  Untested:

import urllib2, StringIO
import ClientForm

url = ''
r = urllib2.urlopen('')
forms = ClientForm.ParseResponse(r)
form = forms[0]

filename = 'c:\temp\file.cif'
f = open(filename)
form.add_file(f, 'application/octet-stream', filename)
r2 = urllib2.urlopen(

print "********************************"


More information about the Python-list mailing list