multipart/form-data in an HTTP client

Jeff Shannon jeff at
Thu Sep 2 01:53:28 CEST 2004

John J. Lee wrote:

>Jeff Shannon <jeff at> writes:
>>I've been using something closely modelled on that Cookbook recipe,
>>without any real problems.  (I've updated it to use
>>HTTP[S]Connection() and return the response object, and in my case I'm
>>connecting to an HTTPS server, but these are trivial modifications.)
>Have you published your function?  If not, please do.

Here it is, for what it's worth.  (Hopefully my mailer won't mangle the 
indentation...)  As I noted, the differences between this and the 
Cookbook recipe are minimal -- I literally copied the recipe into my 
editor and made a few changes.

If I were going to put further effort into polishing it for library use 
(which I probably won't have much opportunity to do), I'd make at least 
two changes.  One would be to set it up to select between HTTP and 
HTTPS.  (It currently tries to determine the protocol from the hostname 
string, but does nothing with that information.)  The other would be to 
enable the file-subpart to add a Content-type header.  (This is 
irrelevant for my particular application, as the form(s) I'm uploading 
to don't care.)

In case it matters to anyone, inasmuch as this code is nearly identical 
to the published recipe, my changes can be considered to be under the 
same license as the original recipe.  If someone feels like using this 
in any way, feel free.

Jeff Shannon
Credit International

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
URL: <>

More information about the Python-list mailing list