skip to Main Content

I have been trying to use the Azure face service through Python and have copy pasted the code from the official site. (https://learn.microsoft.com/en-us/azure/cognitive-services/computer-vision/quickstarts-sdk/identity-client-library?tabs=visual-studio&pivots=programming-language-python). I have a free student benefits account.

I have updated the key and endpoint and let the image links remain as it is. However, I am getting the following error when I run the code.

Person group: 61ec255a-06db-45dd-ac7e-90c9dfac98b0
Traceback (most recent call last):
  File "f:CollegeSEM 6IOTazure codefile.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:UsershpAppDataLocalProgramsPythonPython39libsite-packagesazurecognitiveservicesvisionfaceoperations_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.

I don’t know where I am going wrong. Can someone please point out what’s happening here?

3

Answers


    • We tried to reproduce the issue from our end by following the document provided we are able to run the application successfully as shown below:

    enter image description here

    Verify the below checklist:

    Login or Signup to reply.
  1. Microsoft has limited access to certain features (including the Face API in order to respect their principles of responsible AI) to people who are accredited After filling out their form which you can find on their website.

    Login or Signup to reply.
  2. Like baptistin pointed out, the issue is with the limited access to certain Face API features.
    While the Cognitive Services SDK does not indicate this in detail, you can use plain REST API to do the same query and get to a more detailed error message.
    I used PowerShell to invoke the REST API but you could also use Postman, curl – whichever you prefer.

    $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
    

    The response is a little more detailed than what you get when using the 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"
        }
      }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search