Computer vision | Describe | 401

Hafeez Ali 21 Reputation points
2021-06-07T03:33:18.62+00:00

Hi,

I'm receiving a 401 when using the below sample code provided here: https://westcentralus.dev.cognitive.microsoft.com/docs/services/computer-vision-v3-2/operations/56f91f2e778daf14a499f21f

I have set my subscription key and the body just has a URL, for eg: '{"url":"https://www.shaadidukaan.com/vogue/wp-content/uploads/2019/08/hug-kiss-images.jpg"}'

Again as described on the above-mentioned page.

##### Python 3.2

import http.client, urllib.request, urllib.parse, urllib.error, base64

headers = {
# Request headers
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': '{subscription key}',
}

params = urllib.parse.urlencode({
# Request parameters
'maxCandidates': '1',
'language': 'en',
'model-version': 'latest',
})

try:
conn = http.client.HTTPSConnection('westcentralus.api.cognitive.microsoft.com')
conn.request("POST", "/vision/v3.2/describe?%s" % params, "{body}", headers)
response = conn.getresponse()
data = response.read()
print(data)
conn.close()
except Exception as e:
print("[Errno {0}] {1}".format(e.errno, e.strerror))

Any ideas about what might be the issue?

Thanks,
Hafeez

Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
2,648 questions
0 comments No comments
{count} votes

Accepted answer
  1. svijay-MSFT 5,226 Reputation points Microsoft Employee
    2021-06-07T10:28:06.023+00:00

    @Hafeez Ali , Thanks for your question.

    I tried the above code at my end and unfortunately, I was not able to reproduce the issue at my end. I was able successfully get the response for the image: https://www.shaadidukaan.com/vogue/wp-content/uploads/2019/08/hug-kiss-images.jpg

    The issue might be because of the location / incorrect subscription key.

    Please confirm the subscription key used in the code is same as the one in the resource. The headers should be of the below format :

    headers = {  
    # Request headers  
    'Content-Type': 'application/json',  
    'Ocp-Apim-Subscription-Key': '440......308',  
    
    }  
    

    If it persists, please confirm your region endpoint you are making use of.
    As per your code you are hitting the WestCentralUs.

    conn = http.client.HTTPSConnection('westcentralus.api.cognitive.microsoft.com')  
    

    The endpoint would be different as per the location of the Computer Vision resource. If your resource is not in the WestCentralUS, you will have to change this as per the below.

    103005-image.png

    In my case, the resource is in the WestUS location. Hence the endpoint I've used is :

    conn = http.client.HTTPSConnection('westus.api.cognitive.microsoft.com')  
    

    102909-image.png

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful