How to upload a file
Torsten Bronger
bronger at physik.rwth-aachen.de
Wed Apr 27 10:14:54 EDT 2011
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
http://stackoverflow.com/questions/68477/send-file-using-post-from-a-python-script)
In my module, I do my HTTP request like this:
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookielib.CookieJar()))
opener.open(url, 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. ;-)
Tschö,
Torsten.
--
Torsten Bronger Jabber ID: torsten.bronger at jabber.rwth-aachen.de
or http://bronger-jmp.appspot.com
More information about the Python-list
mailing list