Scripting HTTP POST - multipart/form-data

Jeff Shannon jeff at ccvcorp.com
Mon Jul 19 18:50:21 EDT 2004


I'm looking to script a routine file-upload through an HTTP server 
(which I don't have access to).  I've got specs on the CGI app that 
receives this upload (i.e. field names and expected contents).

However, it looks like urllib/urllib2 won't handle multipart/form-data 
POSTs.  I tried hacking together something with httplib, but I'm 
severely hampered by the fact that I don't know HTTP well enough to know 
what headers I need to send, and my attempts to find (through Google) a 
list of necessary headers haven't turned out too well.  I really don't 
want to have to scour the entire HTTP specs for this...

At a quick glance, it seems that PyCURL may do what I need, but it's... 
well, not exactly user-friendly (at least for someone with zero 
experience with libcurl), and the machine I'm trying to send from (RH9) 
doesn't have libcurl installed.  (I'd prefer to not have to install 
anything just for this, if I can avoid it...)

Is there another (preferably all-python) library that will work for 
this?  Or perhaps a friendly how-to that'll explain what I need to know 
to use httplib?

Jeff Shannon
Technician/Programmer
Credit International




More information about the Python-list mailing list