Python 上 Azure Face API 中面部验证的错误代码请求
Bad code request for face verification in Azure Face API on Python
我正在学习如何使用这个 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.'}}
我看到的唯一区别是
params = {
"faceId1": "03ab5c58-86bb-4eef-a89e-56d4ce76e95b",
"faceId2": "05113848-2c22-4116-8a30-5cde938eec61"
}
更新
应遵循的一些提示
- 确保 API 区域与您的订阅密钥相同
- 确保您使用的是正确的端点,请参阅认知服务中的概览选项卡以获得正确的端点。
这是解决方法。我想通了:
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)
我正在学习如何使用这个 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.'}}
我看到的唯一区别是
params = {
"faceId1": "03ab5c58-86bb-4eef-a89e-56d4ce76e95b",
"faceId2": "05113848-2c22-4116-8a30-5cde938eec61"
}
更新
应遵循的一些提示
- 确保 API 区域与您的订阅密钥相同
- 确保您使用的是正确的端点,请参阅认知服务中的概览选项卡以获得正确的端点。
这是解决方法。我想通了:
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)