以下是我从本地计算机上传kairos文件的代码。
from urllib2 import Request, urlopen
values_enroll = """
{
"image": "/home/neel/project/test5.jpg",
"subject_id": "2",
"gallery_name": "MyGallery"
}
"""
headers_enroll = {
'Content-Type': 'application/json',
'app_id': '2dxxxx79',
'app_key': '08aa31ebdxxxxxxxxxxaa6f6c87f4ea8'
}
request_enroll = Request('https://api.kairos.com/enroll',
data=values_enroll, headers=headers_enroll)
response_body_enroll = urlopen(request_enroll).read()
print response_body_enroll
当我运行此代码时出现错误:
" {"错误":[{" ErrCode":5000,"消息":"发送的图像无效 是jpg或png格式"}]}"
我关注此文档:http://docs.kairosv1.apiary.io/#reference/face-recognition/enroll/post。
现在,我不想从可公开访问的网址上传图片,而是希望从我的本地计算机上传图片,并且可以在从公共网址上传图片时正常工作。
我也尝试过两种解决方案:Error while trying to upload file using kairos 以及解决方案:http://www.projsolution.com/a107-6007-python
答案 0 :(得分:1)
最近我找到了一个解决方案(对我有用):
files = {"image": ("test5.jpg",open("/home/neel/project/test5.jpg","rb"))}
values_enrol = """
{
"subject_id": "2",
"gallery_name": "MyGallery"
}
"""
res = requests.post("https://api.kairos.com/enroll", files=files, data=values_enroll, headers=headers)
p / s:如果删除Content-Type
,它将起作用