My Http connection doesnt work when I'm using Python for PII detection on Azure

Daya Sandhu 21 Reputation points
2021-09-20T15:26:15.153+00:00

My Error is:

Encountered exception. <urllib3.connection.HTTPSConnection object at 0x0000021FA1246E80>: Failed to establish a new connection: [Errno 11002] getaddrinfo failed

I have followed the Azure page in adding my key and the endpoint ,but the connection doesnt work.:

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

key = "<my_key>"
endpoint = "https://identification.cognitiveservices.azure.com/"

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

client = authenticate_client()

def entity_recognition_example(client):

try:
    documents = ["I had a wonderful trip to Seattle last week."]
    result = client.recognize_entities(documents = documents)[0]

    print("Named Entities:\n")
    for entity in result.entities:
        print("\tText: \t", entity.text, "\tCategory: \t", entity.category, "\tSubCategory: \t", entity.subcategory,
                "\n\tConfidence Score: \t", round(entity.confidence_score, 2), "\tLength: \t", entity.length, "\tOffset: \t", entity.offset, "\n")

except Exception as err:
    print("Encountered exception. {}".format(err))

entity_recognition_example(client)

Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
3,598 questions
{count} votes

1 answer

Sort by: Most helpful
  1. romungi-MSFT 48,906 Reputation points Microsoft Employee Moderator
    2021-09-21T07:29:10.827+00:00

    @Daya Sandhu Is there any restriction with network on the machine that you are running this sample? I see you are using your resources custom domain as endpoint but the client is unable to connect to it. The most likely reason for this could be

    1. The access to the endpoint on port 443 from the machine on which this sample is run
    2. The endpoint URL is incorrect.

    Could you please cross verify these scenarios?

    For the first point you can run the same sample from a different machine or check if a proxy is enabled that is restricting access to the endpoint.
    For the second point you can cross check the URL from Azure portal for this resource.

    I have run the sample for test and it seems to work as expected.

    133788-image.png

    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.