0

I am trying to analyze a video via Emotion API by Microsoft using Python 3.2

I am encountering the following error:

b'{ "error": { "code": "Unauthorized", "message": "Access denied due to invalid subscription key. Make sure you are subscribed to an API you are trying to call and provide the right key." } }'

I am using Emotion API subscription key (i have also used the Face API key, and computer vision key just in case).

Code:

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

headers = {
    # Request headers
    'Ocp-Apim-Subscription-Key': '{subscription key}',
}

params = urllib.parse.urlencode({
})

try:
    conn =    http.client.HTTPSConnection('westus.api.cognitive.microsoft.com')
    conn.request("GET", "/emotion/v1.0/operations/{oid}?%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))
Ahsan
  • 1
  • 1

1 Answers1

0

Your code works. Just make sure you wait 10 minutes after generating the API key so that it starts working (it says so in the Azure Portal).

Also, in general for Cognitive Services, make sure that the API key you have corresponds to the region you're trying to hit (West US, etc.)

Maria Ines Parnisari
  • 16,584
  • 9
  • 85
  • 130