我正在尝试转换此curl命令:
curl -X POST -F "images_file=@prez.jpg" "https://gateway-a.watsonplatform.net/visual-recognition/api/v3/detect_faces?api_key={apikey}&version=2016-05-20"
到python post请求。
在手册中使用了this example,但我仍然收到无文件上传错误。
url = {'https://gateway-a.watsonplatform.net/visual-recognition/api/v3/detect_faces'}
images= {'images_file': ('prez.jpg', open('prez.jpg', 'rb'))}
payload = {'api_key': {apikey}, 'version':'2016-05-20'}
r = requests.post(url, files = images, params = payload)
print(r.text)
以下是Watson API的回复:
{
"error": {
"code": 400,
"description": "No images were specified.",
"error_id": "input_error"
},
"images_processed": 1
}
我是否正确上传文件? curl命令工作正常,因此可能不是图像问题。
答案 0 :(得分:1)
这应符合您的卷曲请求。
url = 'https://gateway-a.watsonplatform.net/visual-recognition/api/v3/detect_faces'
images = {'images_file': open('prez.jpg', 'rb')}
payload = {'api_key': "{{{}}}".format(api_key), 'version': '2016-05-20'}
r = requests.post(url, files=images, params=payload)