How to upload a file

Torsten Bronger bronger at
Wed Apr 27 10:14:54 EDT 2011


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.  ;-)


Torsten Bronger    Jabber ID: torsten.bronger at

More information about the Python-list mailing list