pycurl post file的方法

        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()

你可能感兴趣的:(python,File,import)