Is Microsoft Face API verification (face to face) down? Always says bad request and documentation console shows error

允我心安 提交于 2019-12-24 18:17:29

问题


Here is what I've been trying:

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)

I always get this output

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

Also, I've tried the API testing console and it results in an error always for face to face (haven't tried the others) Here's the link to documentation where you can get the links to API testing console. https://southeastasia.dev.cognitive.microsoft.com/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523a


回答1:


Based on the Verify API we could know that faces should be in the body part not in the params

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)

Test Result:

We also could do that easily with 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)


来源:https://stackoverflow.com/questions/52993794/is-microsoft-face-api-verification-face-to-face-down-always-says-bad-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!