Python 之 Object of type bytes is not JSON serializable

欲儿 2020-03-14 01:47:20
是这样的我在利用百度api做一个人脸比对

源代码如下

from aip import AipFace
""" 你的 APPID AK SK """
APP_ID = '18814618'
API_KEY = 'A1bFwZeTGWRlg5MDk4ycu24q'
SECRET_KEY = '186VKOrpAe0Lo1TtzPiTX5NjnExY7KCS'

client = AipFace(APP_ID, API_KEY, SECRET_KEY)


""" 读取图片 """
def get_file_content(filePath):
with open(filePath, 'rb') as fp:
return fp.read()

images = [
get_file_content('D://001.jpg'),
get_file_content('D://002.jpg'),
]

""" 调用人脸比对 """
client.match(images);

""" 如果有可选参数 """
options = {}
options["ext_fields"] = "qualities"
options["image_liveness"] = ",faceliveness"
options["types"] = "7,13"

""" 带参数调用人脸比对 """
result = client.match(images, options)
print (result)




错误提示
Object of type bytes is not JSON serializable

...全文
1811 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
冰风漫天 2020-03-14
  • 打赏
  • 举报
回复
images那边要怎么写

import base64
images = [
 
    {'image': str(base64.b64encode(get_file_content('D://001.jpg')), 'utf-8'), 'image_type': 'BASE64'},
    {'image': str(base64.b64encode(get_file_content('D://002.jpg')), 'utf-8'), 'image_type': 'BASE64'},
]
另外,你下面可选参数那段去了吧,现在传参数也是放images里传的

37,743

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧