question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TextAnalyticsClient throws APIErrorException 'NotFound' in v2.0.0-preview

See original GitHub issue

Note: This is the same Issue affecting the FaceAPI as reported in #4534

Note: v2.0.0-preview does not include an implementation of ServiceClientCredentials, as noted as #4483, which is why I’ve included class ApiKeyServiceClientCredentials : ServiceClientCredentials in the sample code, below.

The following code, using Microsoft.Azure.CognitiveServices.Language.TextAnalytics v2.0.0-preview, throws Microsoft.Azure.CognitiveServices.Language.TextAnalytics.Models.ErrorResponseException:

Operation returned an invalid status code ‘NotFound’

readonly TextAnalyticsClient TextAnalyticsApiClient = new TextAnalyticsClient(new ApiKeyServiceClientCredentials(CognitiveServicesConstants.FaceApiKey));

public static async Task<Dictionary<string, double?>> GetSentiment(List<string> textList)
{
    var textIdDictionary = new Dictionary<string, string>();
    var multiLanguageBatchInput = new MultiLanguageBatchInput(new List<MultiLanguageInput>());

    foreach (var text in textList)
    {
        var textGuidString = Guid.NewGuid().ToString();

        textIdDictionary.Add(textGuidString, text);

        multiLanguageBatchInput.Documents.Add(new MultiLanguageInput(id: textGuidString, text: text));
    }

    var sentimentResults = await TextAnalyticsApiClient.SentimentAsync(multiLanguageBatchInput).ConfigureAwait(false);

    if (sentimentResults?.Errors?.Any() ?? false)
    {
        var exceptionList = sentimentResults.Errors.Select(x => new Exception($"Id: {x.Id}, Message: {x.Message}"));
        throw new AggregateException(exceptionList);
    }

    var resultsDictionary = new Dictionary<string, double?>();

    foreach (var result in sentimentResults?.Documents)
        resultsDictionary.Add(textIdDictionary[result.Id], result?.Score);

    return resultsDictionary;
}

class ApiKeyServiceClientCredentials : ServiceClientCredentials
{
    readonly string _subscriptionKey;

    public ApiKeyServiceClientCredentials(string subscriptionKey) => _subscriptionKey = subscriptionKey;

    public override Task ProcessHttpRequestAsync(System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
    {
        if (request is null)
            throw new ArgumentNullException("request");

        request.Headers.Add("Ocp-Apim-Subscription-Key", _subscriptionKey);

        return Task.FromResult<object>(null);
    }
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
lealcrfcommented, Jun 19, 2019

Do like dev-aritra suggested. Set your endpoint only until microsoft.com, so it looks like, in my case, https://brazilsouth.api.cognitive.microsoft.com and NOT like https://brazilsouth.api.cognitive.microsoft.com/text/analytics/v2.0.

It worked for me.

2reactions
dev-aritracommented, Mar 1, 2019

The workaround is to include the region and specify the URL till microsoft.com So my endpoint looks like https://centralindia.api.cognitive.microsoft.com this and not this https://centralindia.api.cognitive.microsoft.com/text/analytics/v2.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

FaceClient throws APIErrorException 'NotFound' in v2.0.0- ...
The following code, using Microsoft.Azure.CognitiveServices.Vision.Face v2.0.0-preview, throws Microsoft.Azure.CognitiveServices.Vision.
Read more >
Text mining and analysis with the Text Analytics API
The Text Analytics API is a cloud-based service that provides Natural Language Processing (NLP) ... was an error, it will throw a RequestFailedException...
Read more >
azure.ai.textanalytics.TextAnalyticsClient class
The API can be used to analyze unstructured text for tasks such as sentiment analysis, key phrase extraction, entities recognition, and language detection,...
Read more >
Azure Cognitive Services Text Analytics client library for .NET
This article will show you how to summarize text with the extractive summarization API.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found