Python: uploading file via HTTP with pyCurl and Requests

Here is a simple way to upload file in Python. You should have PyCurl installed. import pycurl from cStringIO import StringIO filename=’test_file’ c = pycurl.Curl() c.setopt(c.POST, 1) c.setopt(c.HTTPPOST, [(‘title’, ‘test’), ((‘file’, (c.FORM_FILE, filename)))]) c.setopt(c.VERBOSE, 1) bodyOutput = StringIO() headersOutput = StringIO() c.setopt(c.WRITEFUNCTION, bodyOutput.write) c.setopt(c.URL, “http://upload.example.com” ) c.setopt(c.HEADERFUNCTION, headersOutput.write) c.perform() print bodyOutput.getvalue() Upd. File upload with…