You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Face API禁用returnFaceId时出现JSON解析错误求助

问题原因及修正方案

第一个错误(UnsupportedFeature)

Azure Face API的returnFaceId参数关联人脸标识、验证类功能,这类功能需要额外申请访问权限,免费F0层级默认未开通该权限,因此设置returnFaceId: true时会触发权限报错。

第二个错误(JSON parsing error)

代码中使用requests.post时传入了data=data参数,但请求头已指定Content-Type: application/json,data参数会把字典以表单格式编码发送,而非JSON格式,导致服务器解析失败。

修正后的代码

import requests

BASE_URL = "https://xxxxxxxxxxxxxxx.cognitiveservices.azure.com/face/v1.0/detect"

HEADERS = {
    'Content-Type': 'application/json',
    'Ocp-Apim-Subscription-Key': "[My Key]"  # 替换为你的实际密钥
}

PARAMS = {
    'returnFaceLandmarks': 'true',
    'returnFaceId': 'false',  # 保持false以规避权限问题
    'detectionModel': 'detection_03',
}

url = "https://u.cubeupload.com/Johann/test1.jpg"

data = {'url': url}

# 关键修正:将data=data改为json=data,确保发送JSON格式数据
r = requests.post(BASE_URL, json=data, headers=HEADERS, params=PARAMS)

print(r.json())

额外说明

如果确实需要启用returnFaceId=true的功能,需向Azure申请该功能的访问权限,审批通过后才能正常调用。

内容的提问来源于stack exchange,提问作者John

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 06:10:31