【发布时间】:2016-09-17 20:38:16
【问题描述】:
我正在尝试发送二进制图像文件来测试 Microsoft Face API。使用 POSTMAN 效果很好,我按预期返回了 faceId。但是,我尝试将其转换为 Python 代码,但它目前给了我这个错误:
{"error": {"code": "InvalidImage", "message": "Decoding error, image format unsupported."}}
我读过这个SO post,但它没有帮助。这是我发送请求的代码。我试图模仿邮递员正在做的事情,例如用标题application/octet-stream 标记它,但它不起作用。有什么想法吗?
url = "https://api.projectoxford.ai/face/v1.0/detect"
headers = {
'ocp-apim-subscription-key': "<key>",
'content-type': "application/octet-stream",
'cache-control': "no-cache",
}
data = open('IMG_0670.jpg', 'rb')
files = {'IMG_0670.jpg': ('IMG_0670.jpg', data, 'application/octet-stream')}
response = requests.post(url, headers=headers, files=files)
print(response.text)
【问题讨论】:
标签: python azure python-requests azure-api-apps microsoft-cognitive