首页 > 解决方案 > 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 时,我得到了这个错误,所以希望你能解决它。

标签: pythonjsonpython-2.7

解决方案


您应该将响应解析为 JSON:

responseData = response.json()

推荐阅读