Проверка Microsoft Face API (лицом к лицу) вниз?Всегда говорит неверный запрос, а в документации отображается ошибка - PullRequest
0 голосов
/ 25 октября 2018

Вот что я пытался:

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,'Content-Type':'application/json'}
params = {
    "faceId1": "a1cadf80-d780-4b6a-8cef-717548a07e51",
    "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.'}}

Кроме того, я пробовал консоль тестирования API, и это приводит кошибка всегда лицом к лицу (другие не пробовали) Вот ссылка на документацию, где вы можете получить ссылки на консоль тестирования API.https://southeastasia.dev.cognitive.microsoft.com/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523a

1 Ответ

0 голосов
/ 26 октября 2018

Основываясь на API проверки, мы можем знать, что грани должны быть в теле части, а не в параметрах

subscription_key = "xxxx"
assert subscription_key
import json
face_api_url = 'https://westus.api.cognitive.microsoft.com/face/v1.0/verify'
headers = {'Ocp-Apim-Subscription-Key': subscription_key,'Content-Type':'application/json'}
faces = {
    "faceId1": "xxxxxxxx",
    "faceId2": "xxxxxx"
}

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

Результат теста:

enter image description here

Мы также можем легко сделать это с помощью Python SDK

import cognitive_face as CF
KEY = 'xxxxxx'  # Replace with a valid subscription key (keeping the quotes in place).
CF.Key.set(KEY)

BASE_URL = 'https://{location}.api.cognitive.microsoft.com/face/v1.0'  # Replace with your regional Base URL
CF.BaseUrl.set(BASE_URL)
result = CF.face.verify("faceId1","faceId2")
print(result)
...