How to upload a file

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Thu Apr 28 05:22:18 EDT 2011


En 2011年4月27日 11:14:54 -0300, Torsten Bronger 
<bronger at physik.rwth-aachen.de> 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
> 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. ;-)

This particular battery isn't included (yet - see 
http://bugs.python.org/issue3244)
but this little library may help:
https://bitbucket.org/chrisatlee/poster
-- 
Gabriel Genellina


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /