404 error: resource not found when using text analytics client library

Shimmur 1 Reputation point
2021-03-07T18:10:46.297+00:00

I've used the code from the quickstart guide on using text analytics client library.

    documents = ['It was a bleak experience attending this language school for the exam. It was very hard to find. ']
    response = client.analyze_sentiment(documents=documents)[0]
    print("Document Sentiment: {}".format(response.sentiment))
    print("Overall scores: positive={0:.2f}; neutral={1:.2f}; negative={2:.2f} \n".format(
    response.confidence_scores.positive,
    response.confidence_scores.neutral,
    response.confidence_scores.negative,
))

And I've implemented authentication using the following:

key = "1234556"
base_url = "https://myresource.cognitiveservices.azure.com/"
path = "/text/analytics/v3.0/sentiment"
endpoint = base_url + path

from azure.ai.textanalytics import TextAnalyticsClient
from azure.core.credentials import AzureKeyCredential

def authenticate_client():
    ta_credential = AzureKeyCredential(key)
    text_analytics_client = TextAnalyticsClient(
            endpoint=endpoint, 
            credential=ta_credential)
    return text_analytics_client

client = authenticate_client()

However I get the error: 404 Resource not found.
Do I need to add a dependency in my project folder somehow or something else is amiss?
Greatly appreciate any and all help and pointers.

Azure AI Language
Azure AI Language
An Azure service that provides natural language capabilities including sentiment analysis, entity extraction, and automated question answering.
407 questions
Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
2,800 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Ramr-msft 17,736 Reputation points
    2021-03-08T13:47:56.24+00:00

    @Shimmur Thanks for the question. We are able to get the sentiment successfully using client library. Here is the sample code for single and multiple documents to analyze sentiment.

    You can set endpoint and apiKey based on an environment variable, a configuration setting, or any way that works for your application.

    var client = new TextAnalyticsClient(new Uri(endpoint), new AzureKeyCredential(apiKey));

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.