python - AttributeError:“unicode”对象没有属性“image_id”
问题描述
我有这个使用 face++ 服务的图像处理 python 代码。
我的代码是:
import requests
import json
API_KEY = "***************************"
API_SECRET = "**************************"
detect = {
'api_key': (None, API_KEY),
'api_secret': (None, API_SECRET),
'image_file': ('image_file.jpg', open('image_file.jpg', 'rb')),
'return_attributes': (None, 'gender,age'),
}
response = requests.post('https://api-us.faceplusplus.com/facepp/v3/detect', files=detect)
responseData = (response.text)
print(responseData)
print("----------------------------------------------------")
print(responseData.image_id)
以上给出错误AttributeError: 'unicode' object has no attribute 'image id'
所以当我最后打印 image_id 时,我得到了这个错误,所以希望你能解决它。
解决方案
您应该将响应解析为 JSON:
responseData = response.json()
推荐阅读
- javascript - 渲染组件时不触发 useEffect
- kotlin - 检测具体类型中的可空性
- javascript - 使用 javascript 创建 SVG 元素
- php - 如何在我的自定义 MVC 框架中设置 Flash 消息?
- linux - for循环变量中的Bash调用变量
- flutter - 如何将 Group_list 包中的 Classed Contructor list(name) 添加到按日期进行群聊?在颤振?
- sql - 错误 PLS-00382 (283: 17):PLS-00382:表达式类型错误
- javascript - 如果用户在 JavaScript 中选择取消按钮,如何重新加载提示?
- mysql - 如何解决这个 MySQL COUNT 查询?
- node.js - 用于聚合 Firestore 字段值的 Typescript 云函数