TextAnalyticsClient throws APIErrorException 'NotFound' in v2.0.0-preview
See original GitHub issueNote: 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:
- Created 5 years ago
- Comments:14 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
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 thishttps://centralindia.api.cognitive.microsoft.com/text/analytics/v2.0