Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uploading a file via pyCurl

I am trying to convert the following curl code into pycurl. I do not want to use requests. I need to use pycurl because requests is not fully working in my old python version.

curl
-X POST
-H "Accept-Language: en"
-F "[email protected]"
-F "[email protected]"
"https://gateway-a.watsonplatform.net/visual-recognition/api/v3/classify?api_key={api-key}&version=2016-05-20"

Can someone please show me how to write it out in PyCurl?

like image 222
v33j Avatar asked Jul 15 '16 10:07

v33j


1 Answers

import pycurl
c = pycurl.Curl()
c.setopt(c.URL, 'https://gateway-a.watsonplatform.net/visual-recognition/api/v3/classify?api_key={api-key}&version=2016-05-20')
c.setopt(c.POST, 1)
c.setopt(c.HTTPPOST, [("images_file", (c.FORM_FILE, "fruitbowl.jpg"))])
c.setopt(c.HTTPPOST, [("parameters", (c.FORM_FILE, "myparams.json"))])
c.setopt(pycurl.HTTPHEADER, ['Accept-Language: en'])
c.perform()
c.close()
like image 61
Kenan Kocaerkek Avatar answered Sep 28 '22 15:09

Kenan Kocaerkek