【问题标题】:Azure Cognitive Services: Face Find Similar 'BadArgument', 'Argument faceListId and faceIds cannot be provided at the same time.'.'Azure 认知服务:人脸查找相似的“BadArgument”、“参数 faceListId 和 faceIds 不能同时提供。”。
【发布时间】:2019-01-08 15:17:55
【问题描述】:

我是 Azure 认知服务的新手。我正在使用 python 3.5 和 Azure Face 服务,特别是“Face - Find Similar”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()

【问题讨论】:

    标签: json python-3.x azure microsoft-cognitive face


    【解决方案1】:

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

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

    或

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

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

    【讨论】:

      猜你喜欢
      • 2017-05-04
      • 1970-01-01
      • 2018-09-18
      • 1970-01-01
      • 1970-01-01
      • 2017-12-29
      • 1970-01-01
      • 1970-01-01
      • 2021-08-31
      相关资源
      最近更新 更多