How to upload a file

Gabriel Genellina gagsl-py2 at
Thu Apr 28 05:22:18 EDT 2011

En Wed, 27 Apr 2011 11:14:54 -0300, Torsten Bronger  
<bronger at> escribió:

> Hallöchen!
> I'm skimming through the various recipies for uploading a file via
> HTTP.  Unfortunately, all of them are awkward but also rather old.
> (See for example
> In my module, I do my HTTP request like this:
> opener =  
> urllib2.build_opener(urllib2.HTTPCookieProcessor(cookielib.CookieJar()))
>, urllib.urlencode(data, doseq=True))
> Well, and now I'd also like to include a file upload to the POST
> data.  The solution should use urllib2, otherwise I'd have to change
> most of my existing code.
> If you now say "Torsten, unfortunately it *is* so complicated" I'll
> jump through the hoops, but I'd love to hear that with Python 2.6.5
> there's an easier way.  ;-)

This particular battery isn't included (yet - see
but this little library may help:

Gabriel Genellina

More information about the Python-list mailing list