curl-and-python

how to POST file upload with pycurl

From: PoisoneR <poisonertmp_at_gmail.com>
Date: Fri, 2 Mar 2007 14:50:40 +0200

Hi,
I am trying to submit file via HTTP POST.
But I can't find any examples in the net.
I tried somethin like this

def sendupload():
       c = pycurl.Curl()
       c.setopt(c.USERAGENT, ua)
       url = 'http://localhost/post.php'
       c.setopt(c.POST, 1)
       c.setopt(c.URL, url)
       f = open('clip.3gp', 'rb')
       c.setopt(c.FORM_FILE, f)
       fc = 'cookie.txt'
       c.setopt(c.COOKIEFILE, fc)
       c.setopt(c.COOKIEJAR, fc)
       f = open('sendupload.html', 'wb')
       c.setopt(c.WRITEDATA, f)
       c.setopt(c.VERBOSE, 1)
       c.perform()
       c.close()

but it doesn't work

   c.setopt(c.FORM_FILE, f)
TypeError: files are not supported for this option

i tried and with filename string instead file object, but is the same.
What variable type this wants?
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-python
Received on 2007-03-02