i trying convert curl call --form data python
curl -h "x-api-token:xxxxxxxxxxxxxxxxxxxxxxxxxx" -x post \ --form upload=@2015-07-02-fiesta-ek-malware-payload.exe \ --form "owner=username" https://192.168.1.198/rapi/samples/basic
what have tried:
url = 'https://%s/rapi/samples/basic' % hostname q = request(url) q.add_header('x-api-token', 'xxxxxxxxxxxxxxxxxxxxxxxxxx') q.add_header('content-type', 'multipart/form-data; upload=@%s' % filename) q.add_header('content-type', 'multipart/form-data; owner=username') = urlopen(q).read()
the return default listing of submitted samples. sure not getting header data.
i use example of passing multiple form data headers.
thanks.
a sample call using unirest
import unirest # consume async post request def consumepostrequestsync(): params = {'test1':'param1','test2':'param2'} # need pass dummy variable open method # unirest not provide variable shift between # application-x-www-form-urlencoded , # multipart/form-data params['dummy'] = open('dummy.txt', 'r') url = 'http://httpbin.org/post' headers = {"accept": "application/json"} # call service headers , params response = unirest.post(url, headers = headers,params = params) print "code:"+ str(response.code) print "******************" print "headers:"+ str(response.headers) print "******************" print "body:"+ str(response.body) print "******************" print "raw_body:"+ str(response.raw_body) # post sync request multipart/form-data consumepostrequestsync()
you can check blog more details http://stackandqueue.com/?p=57
Comments
Post a Comment