import pycurl
from urllib import urlencode
ch = pycurl.Curl()
timeout = 360
ch.setopt(pycurl.CONNECTTIMEOUT, timeout)
ch.setopt(pycurl.URL, ‘http://url‘)
post_data = [
(‘file1‘, (pycurl.FORM_FILE, FILENAME))
...
]
ch.setopt(pycurl.HTTPPOST, post_data)
b = StringIO.StringIO()
ch.setopt(pycurl.WRITEFUNCTION, b.write)
try:
ch.perform()
print ‘data=%s‘ % b.getvalue()
except Exception, e:
print ‘Connection error: %s‘ % str(e)
ch.close()
原文地址:http://pythonfan.blog.51cto.com/9764080/1599710