gpt4 book ai didi

python - 在kairos python中上传本 map 片

转载 作者:太空宇宙 更新时间:2023-11-03 14:51:59 27 4
gpt4 key购买 nike

下面是我从本地计算机在 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

当我运行此代码时,出现错误:

"{"Errors":[{"ErrCode":5000,"Message":"an invalid image was sent must be jpg or png format"}]}"

我正在关注此文档:http://docs.kairosv1.apiary.io/#reference/face-recognition/enroll/post .

现在,我想从本地计算机上传图像,而不是从可公开访问的 URL 上传图像,并且从可公开访问的 URL 上传图像时效果很好。

我还尝试了以下两种解决方案:Error while trying to upload file using kairos还有这个解决方案:http://www.projsolution.com/a107-6007-python

最佳答案

最近我找到了一个解决方案(它对我有用):

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就可以了

关于python - 在kairos python中上传本 map 片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45831862/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com