php - pycurl PostFields option usage -


i'm trying use pycurl upload file processmaker. app, self.usr, , doc strings. file django file field object. i'm passing object. i'm sure i'm passing incorrect object/type/thing attach_file field.

the working php postfields definition looks this:

$params = array ( 'attach_file'  => '@/home/test.txt', 'application'  => $resultcase->caseid, 'index'        => 1, 'usr_uid'      => $orandomuser->guid, 'doc_uid'      => '3154812864d55a6e017ff65089604572', 'app_doc_type' => 'input', 'title'        => "initial document".date("y-m-d h:i:s"), 'comment'      => "this document uploaded system"  curl_setopt($ch, curlopt_postfields, $params); 

and broken python:

    c = pycurl.curl()     data = [             ('attach_file', (pycurl.readfunction, file.read)),             ('application', app),               ('index' , 1),             ('usr_uid', self.usr),             ('doc_uid', doc),             ('app_doc_type', 'input')            ]      post = urllib.urlencode(data)      print post      url = "http://192.168.51.155/sysworkflow/en/green/services/upload"      c.setopt(pycurl.url, url)     c.setopt(pycurl.verbose, 1)     c.setopt(pycurl.post, 1)     c.setopt(pycurl.postfields, post)      c.perform()      c.close() 

any ideas?

i found way solve own issue. here did, using poster located here: http://atlee.ca/software/poster/ did following:

from poster.streaminghttp import register_openers import poster  register_openers()  url = "http://192.168.51.155/sysworkflow/en/green/services/upload"  params = {  'application' : app,   'index' : 1, 'usr_uid' : self.usr, 'doc_uid' : doc, 'app_doc_type' : 'input', 'title' : 'test', 'attach_file' : open(file.path, "rb") }  datagen, headers = poster.encode.multipart_encode(params) request = urllib2.request(url, datagen, headers) result = urllib2.urlopen(request) print result.read() 

much easier use pycurl! problem first attempt postfields can't accept files (without wrangling) , using httppost option work files difficult working both file data , field data.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -