Azure-sdk-for-net: FaceClient throws APIErrorException 'NotFound' in v2.0.0-preview

Created on 10 Jul 2018  ·  12Comments  ·  Source: Azure/azure-sdk-for-net

The following code, using Microsoft.Azure.CognitiveServices.Vision.Face v2.0.0-preview, throws Microsoft.Azure.CognitiveServices.Vision.Face.Models.APIErrorException:

Operation returned an invalid status code 'NotFound'

readonly FaceClient FaceApiClient = new FaceClient(new ApiKeyServiceClientCredentials(CognitiveServicesConstants.FaceApiKey));

public static async Task<List<Emotion>> GetEmotionResults(Stream photo)
{
    var faceApiResponseList = await FaceApiClient.Face.DetectWithStreamAsync(photo, returnFaceAttributes: new List<FaceAttributeType> { { FaceAttributeType.Emotion } }).ConfigureAwait(false);
    return faceApiResponseList.Select(x => x.FaceAttributes.Emotion).ToList();
}
Cognitive Services Service Attention

Most helpful comment

@sebasjian Use the Base URL of the endpoint instead of the full endpoint url.

E.g., use https://westus.api.cognitive.microsoft.com instead of of https://westus.api.cognitive.microsoft.com/face/v1.0

I opened this Issue which addresses that problem: https://github.com/Azure/azure-sdk-for-net/issues/4633

All 12 comments

Workaround

Update the Endpoint to use the base url containing the specific Azure Region of the Cognitive Service instance as noted in the API docs, .e.g https://[location].api.cognitive.microsoft.com/

Example

In this example, I am using the westus region for the location because that is the region in which my Cognitive Service Face API resource in Azure.

readonly FaceClient FaceApiClient = new FaceClient(new ApiKeyServiceClientCredentials(CognitiveServicesConstants.FaceApiKey))
{
    Endpoint ="https://westus.api.cognitive.microsoft.com/"
});

public static async Task<List<Emotion>> GetEmotionResults(Stream photo)
{
    var faceApiResponseList = await FaceApiClient.Face.DetectWithStreamAsync(photo, returnFaceAttributes: new List<FaceAttributeType> { { FaceAttributeType.Emotion } }).ConfigureAwait(false);
    return faceApiResponseList.Select(x => x.FaceAttributes.Emotion).ToList();
}

Adding @noellelacharite for visibility

Please add label:"Cognitive Services". Thanks.

@LukeBayler I don't have permissions to add labels

Did anyone find a solution to this?

I am getting the same error, but I definitely instantiated the FaceClient with the same endpoint specified in my MS account

@sebasjian Use the Base URL of the endpoint instead of the full endpoint url.

E.g., use https://westus.api.cognitive.microsoft.com instead of of https://westus.api.cognitive.microsoft.com/face/v1.0

I opened this Issue which addresses that problem: https://github.com/Azure/azure-sdk-for-net/issues/4633

@sebasjian Use the Base URL of the endpoint instead of the full endpoint url.

E.g., use https://westus.api.cognitive.microsoft.com instead of of https://westus.api.cognitive.microsoft.com/face/v1.0

I opened this Issue which addresses that problem: #4633

Thank you @brminnick
This worked wonderfully.

Hi all,

we faced the same issue on applying the workaround above but still fail.
https://southeastasia.api.cognitive.microsoft.com/
https://southeastasia.api.cognitive.microsoft.com/face/v1.0
https://southeastasia.api.cognitive.microsoft.com/face/v1.0/detect

於 Microsoft.Azure.CognitiveServices.Vision.Face.Models.APIErrorException 擲回例外狀況: 'mscorlib.dll'
GetAllPersonNamesAsync: Operation returned an invalid status code 'NotFound'

Please advice. Thanks.

@sebasjian Use the Base URL of the endpoint instead of the full endpoint url.

E.g., use https://westus.api.cognitive.microsoft.com instead of of https://westus.api.cognitive.microsoft.com/face/v1.0

I opened this Issue which addresses that problem: #4633

This worked for me!

Hi All,

Closing this ticket as the Azure portal now displays and endpoint consistent with the input for the SDK. Please re-open if this issue still persists

Thanks,
Chris

In azure portal Endpoint is given as "https://westcentralus.api.cognitive.microsoft.com/face" , hence when user use that endpoint , the sdk internal try to create endpoint according to the operation user using. For e.g. by calling method detect_with_url() , it will convert the endpoint to "https://westcentralus.api.cognitive.microsoft.com/face/v1.0/detect" which right. But the endpoint shown in portal will get converted into this "https://westcentralus.api.cognitive.microsoft.com/face/face/v1.0/detect" which lead to APIErrorException. Hence as suggested by @brminnick, just use the base url.

Was this page helpful?
0 / 5 - 0 ratings