在Python上的Azure Face API中进行面部验证的错误代码请求

时间:2018-10-25 10:42:11

标签: python azure azure-cognitive-services face-api

我正在学习如何使用此API,首先,我想到了运行一个简单的程序,结果是这样: 代码:

subscription_key = "**"
assert subscription_key

face_api_url = 'https://southeastasia.api.cognitive.microsoft.com/face/v1.0/verify'




headers = {'Ocp-Apim-Subscription-Key': subscription_key}
params = {
    'faceId1': '03ab5c58-86bb-4eef-a89e-56d4ce76e95b',
    'faceId2': '05113848-2c22-4116-8a30-5cde938eec61'
}


import requests
from pprint import pprint
response  = requests.post(face_api_url, headers=headers, params=params)
faces = response.json()
pprint(faces)

输出:

{'error': {'code': 'BadArgument', 'message': 'Request body is invalid.'}}

2 个答案:

答案 0 :(得分:1)

解决方法如下。我想通了:

import json
subscription_key = "**"
assert subscription_key

face_api_url = 'https://centralindia.api.cognitive.microsoft.com/face/v1.0/verify'


headers = {'Ocp-Apim-Subscription-Key': subscription_key,'Content-Type':'application/json'}
params = {
    "faceId1": "d4f201e1-8372-4295-ab91-5a148d5932e8",
    "faceId2": "948fb955-5384-42e2-8623-2e44127163f6"
}

body1=json.dumps(params)
import requests
from pprint import pprint
response  = requests.post(face_api_url, headers=headers, data=body1)
faces = response.json()
pprint(faces)

答案 1 :(得分:0)

我唯一的区别是

params = {
    "faceId1": "03ab5c58-86bb-4eef-a89e-56d4ce76e95b",
    "faceId2": "05113848-2c22-4116-8a30-5cde938eec61"
}

更新

应遵循的一些提示

  1. 确保API区域与您的订阅密钥相同
  2. 确保您使用的是正确的端点,请参阅认知服务中的“概述”标签以获取正确的端点。