我正在尝试使用kairos API注册个人资料照片。我有一个以下的python代码。
我的python脚本:
AsyncStorage.getItem('searches', (err, result) => { // err indicating the error
console.log("Storage Data(String):", result); // print is string format
console.log("Storage Data(Object):", JSON.parse(result)); // print is json format
})
但是,我收到了一个错误:
#!/usr/bin/python3
import requests
import io
import http.client
import base64
import json
import glob, os
from os.path import basename
dir_path = "/home/Kairos/profiles/msc/"
os.chdir(dir_path)
for file in glob.glob("*.*"):
img_path = file
print(img_path)
files = {'image': (img_path, open(dir_path + img_path, 'rb'), 'image/jpg', {'Expires': '0'})}
headers = {
'app_id': "xxxx",
'app_key': "xxxxxxxxxxxxxxxxxxxxxx",
}
values_enrol = {
'subject_id':'msc',
'gallery_name':'mscGallary'
}
res = requests.post('https://api.kairos.com/enroll', headers=headers, files=files, data=values_enrol)
print(res.content)
我在这里做错了什么?请有人帮助我。
提前致谢。
答案 0 :(得分:0)
我找到了解决方案:
def build_payload(file):
if file is not None:
image = extract_base64_contents(file)
else:
image = url
values_enrol = {
'image': image,
'gallery_name': sys.argv[1],
}
return dict(values_enrol)
def extract_base64_contents(file):
with open(file, 'rb') as fp:
image = base64.b64encode(fp.read()).decode('ascii')
return image