本文介绍了通过pyCurl上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将以下curl代码转换为pycurl.我不想使用请求.我需要使用pycurl,因为请求在我的旧python版本中无法完全正常工作.

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"

有人可以告诉我如何在PyCurl中写出来吗?

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

推荐答案

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

这篇关于通过pyCurl上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-12 06:54