0

我正在学习如何使用这个 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.'}}
4

2 回答 2

2

以下是如何解决它。我想到了:

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)
于 2018-10-26T10:51:05.393 回答
0

我看到的唯一区别是

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

更新

应该遵循的一些提示

  1. 确保 API 区域与您的订阅密钥相同
  2. 确保您使用的是正确的端点,请参阅认知服务中的概览选项卡以获取正确的端点。
于 2018-10-25T14:25:49.353 回答