运行快速入门代码时出现 Azure Face 服务无效请求 API 错误

问题描述 投票:0回答:4

我一直在尝试通过Python使用Azure人脸服务,并从官方网站复制粘贴了代码。 (https://learn.microsoft.com/en-us/azure/cognitive-services/computer-vision/quickstarts-sdk/identity-client-library?tabs=visual-studio&pivots=programming-language-python)。我有一个免费的学生福利帐户。

我已经更新了密钥和端点,并让图像链接保持原样。但是,当我运行代码时,出现以下错误。

Person group: 61ec255a-06db-45dd-ac7e-90c9dfac98b0
Traceback (most recent call last):
  File "f:\College\SEM 6\IOT\azure code\file.py", line 43, in <module>
    face_client.person_group.create(person_group_id=PERSON_GROUP_ID, name=PERSON_GROUP_ID, recognition_model='recognition_04')
  File "C:\Users\hp\AppData\Local\Programs\Python\Python39\lib\site-packages\azure\cognitiveservices\vision\face\operations\_person_group_operations.py", line 121, in create
    raise models.APIErrorException(self._deserialize, response)
azure.cognitiveservices.vision.face.models._models_py3.APIErrorException: (InvalidRequest) Invalid request has been sent.

我不知道我哪里错了。有人可以指出这里发生了什么吗?

python azure api azure-cognitive-services
4个回答
0
投票
  • 我们尝试按照文档重现该问题,前提是我们能够成功运行应用程序,如下所示:

验证以下清单:


0
投票

微软对某些功能(包括 Face API,以尊重其负责任的人工智能原则)的访问权限有限,只有在填写了表格(您可以在其网站上找到)后获得认可的人员。


0
投票

就像 baptistin 指出的那样,问题在于对某些 Face API 功能的访问受到限制。 虽然认知服务 SDK 没有详细说明这一点,但您可以使用普通 REST API 执行相同的查询并获取更详细的错误消息。 我使用 PowerShell 来调用 REST API,但您也可以使用 Postman、curl - 无论您喜欢哪种。

$cognitiveServicesName  = 'yourCognitiveServiceAccountName'
$resourceGroupName      = 'yourResourceGroupName'

$csUri      = (Get-AzCognitiveServicesAccount -Name $cognitiveServicesName -ResourceGroupName $resourceGroupName).Endpoint+'/face/v1.0/detect?returnFaceId=true'
$accessKey  = (Get-AzCognitiveServicesAccountKey -Name $cognitiveServicesName -ResourceGroupName $resourceGroupName).Key1


$headers = @{
    "Content-Type"              = "application/json"
    "Ocp-Apim-Subscription-Key" = $accessKey
}

$body = @{
    url = 'urlToYourImage'
} | ConvertTo-Json

Invoke-RestMethod -Method Post -Uri $csUri -Headers $headers -Body $body | ConvertTo-Json

响应比使用 SDK 时得到的更详细一点:

{
  "error": {
    "code": "InvalidRequest",
    "message": "Invalid request has been sent.",
    "innererror": {
      "code": "UnsupportedFeature",
      "message": "Feature is not supported. Please apply for access at https://aka.ms/facerecognition"
    }
  }
}

0
投票

我提交了要求对面部 API 功能进行特殊访问的表单,并且我也得到了访问这些 API 的确认,但我仍然收到相同的错误显示:无效请求。任何帮助将不胜感激!

Screenshot of the error

© www.soinside.com 2019 - 2024. All rights reserved.