Microsoft Face API验证(面对面)是否向下?总是说错误的请求,文档控制台显示错误 [英] Is Microsoft Face API verification (face to face) down? Always says bad request and documentation console shows error

查看:116
本文介绍了Microsoft Face 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,'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

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

推荐答案

基于验证API,我们可以知道面部应该在 body 部分而不是 params

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)

测试结果:

我们还可以使用python SDK轻松做到这一点

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)

这篇关于Microsoft Face API验证(面对面)是否向下?总是说错误的请求,文档控制台显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆