json - Azure 认知服务 : Face Find Similar 'BadArgument' , 'Argument faceListId and faceIds cannot be provided at the same time.' 。'

标签 json python-3.x azure azure-cognitive-services face

我是 Azure 认知服务的新手。我正在使用 python 3.5 和 Azure Face 服务,特别是“Face - Find Comparison”API。我在格式化 Post JSON 正文时遇到错误。文档说我应该提供一个单一的faceId或面部列表中的面部列表,例如“extended_family”。就我而言,我想使用面部列表。我不知道如何格式化 JSON 中的 FaceID 参数,以便调用处理面部列表。我尝试了不同的替代方法来将faceId设置为“{}”或“Null”、“”、“False”,但这会导致错误。

下面是我的 POST 的 JSON 正文:

{'faceId': '97522b8b-02b6-4115-99e0-6dc1f5d45f51', 'faceIds': ['97522b8b-   02b6-4115-99e0-6dc1f5d45f51', '0ca8f3e4-edf1-4c14-b926-3b47eae7e29c', '2fadbb12-b10b-4761-aaaa-c50f1dc765c3', '56f464d5-b388-4fc7-9051-6991cf5f1d0d', '29931480-632e-40b6-aa0c-9e03e36e95f9', '7a8085b2-2013-4742-a51a-a5543a0347e8'], 'faceListId': 'extended_family', 'maxNumOfCandidatesReturned': 20, 'mode': 'matchPerson'}  

由于 FaceId 已填充,我得到:

error:  'code': 'BadArgument', 'message': 'Argument faceListId and faceIds cannot be provided at the same time.'

如果我将faceId留空,例如:

{'faceId': '', 'faceIds': ['824e3d83-a94f-4ef2-949e-55a55b2ef256', '51f3c1a5-4e16-4b14-89fa-f1342a2c46ec', '0480d2e0-ff05-44de-b3d8-94408277b1c5', 'c7d767fb-0fbe-46c8-b7af-2c8f675bfd8d', 'ca7e82a7-cd3f-417b-bffa-77c9d47c1439', 'f7130e90-9e1f-428a-a773-93c87932a420'], 'faceListId': 'extended_family', 'maxNumOfCandidatesReturned': 20, 'mode': 'matchPerson'}

我得到以下信息:

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

如果我从 JSON 中删除 FaceId 术语:

{'faceIds': ['690feffd-5c86-47d7-ac3c-224b0eafa90f', '936564e0-31aa-43e3-916e-c7b236bea8e0', '614c04cb-4375-44c8-b393-89d64b4c1ebd', 'a29f8e5c-50ba-4bb8-8bf8-98e356a9125a', '073d7865-2aaf-4806-9bef-ddca478137ea', '7e416e83-5973-4aa1-b1fc-3a25b5174bb3'], 'faceListId': 'andersen_extended_family', 'maxNumOfCandidatesReturned': 20, 'mode': 'matchPerson'}
{'error': {'code': 'BadArgument', 'message': 'Face ID is invalid.'}}

我的代码如下:

facelist = list()  #This is populated upstream using the Face Detect API
facelistid = 'extended_family'
faceid = ''

payload = {'faceId': faceid, 'faceIds':facelist,'faceListId':facelistid, 'maxNumOfCandidatesReturned':20,'mode': "matchPerson"}
req = requests.post(serviceurlpersongroup, data = json.dumps(payload)  , headers = {'Ocp-Apim-Subscription-Key': key})
jinfo = req.json()

最佳答案

正如错误消息所解释的那样,不应同时提供faceListIdfaceIds(不是faceId)。所以你使用的payload应该是

payload = {'faceId': faceid, 'faceListId': facelistid, 'maxNumOfCandidatesReturned': 20, 'mode': "matchPerson"}

payload = {'faceId': faceid, 'faceIds': facelist, 'maxNumOfCandidatesReturned': 20, 'mode': "matchPerson"}

如果您有任何其他问题,请随时更新。

关于json - Azure 认知服务 : Face Find Similar 'BadArgument' , 'Argument faceListId and faceIds cannot be provided at the same time.' 。',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43302933/

相关文章:

c# - 未发送每个名称/值对时在 c# 中解析 json

python - 有没有办法将 numpy 数组映射到某个数据框?

windows - 通过python更改Windows 10中的桌面背景

Python如何从我的列表中列出某些数字

azure - 使用 Asp .NET Core 的 Multi-Tenancy Web 应用程序登录问题

json - 如何在 elasticsearch 中存储大的 JSON 字符串?

java - REST 服务 PATCH API 示例

javascript - 使用 PHP 在 javascript 函数中检索 json

java - 如何通过 azure 设备配置服务将自定义错误消息从 azure 函数发送到 iot 设备?

azure - 数据库重新配置失败