Which endpoint should I be using for Text analytics API connection?

Vinny 6 Reputation points
2020-07-31T11:10:47.043+00:00

I am following the QuickStart Python tutorial for using the Text Analytics API and it suggests saving your endpoint and key from the deployed resource i.e. 'Key 1' and 'endpoint' url.

key = "<paste-your-text-analytics-key-here>"
endpoint = "<paste-your-text-analytics-endpoint-here>"

I then use:

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()

the above should connect to the API.

At the moment when I run one of the features, for example, sentiment analysis, as per:

def sentiment_analysis_example(client):

documents = ["I had the best day of my life. I wish you were there with me."]
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,
))
for idx, sentence in enumerate(response.sentences):
    print("Sentence: {}".format(sentence.text))
    print("Sentence {} sentiment: {}".format(idx+1, sentence.sentiment))
    print("Sentence score:\nPositive={0:.2f}\nNeutral={1:.2f}\nNegative={2:.2f}\n".format(
        sentence.confidence_scores.positive,
        sentence.confidence_scores.neutral,
        sentence.confidence_scores.negative,
    ))

I get the following error:

ValueError: The value provided for the url part Endpoint was incorrect, and resulted in an invalid url

Azure AI Language
Azure AI Language
An Azure service that provides natural language capabilities including sentiment analysis, entity extraction, and automated question answering.
353 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,367 questions
0 comments No comments
{count} vote

2 answers

Sort by: Most helpful
  1. Destin Joy 1,866 Reputation points
    2020-07-31T13:50:19.457+00:00

    It seems you are passing a wrong end point.Go to test API resource and find out the end point .Provide the end point then it should work.

    2 people found this answer helpful.
    0 comments No comments

  2. YutongTie-MSFT 46,406 Reputation points
    2020-08-04T16:26:18.78+00:00

    Hi,

    Please go to the Azure portal. If the Text Analytics resource you created in the Prerequisites section deployed successfully, click the Go to Resource button under Next Steps. You can find your key and endpoint in the resource's key and endpoint page, under resource management.

    Regards,
    Yutong

    0 comments No comments