Python 3.x Microsoft情感视频API Python 3.2
我正在尝试使用Python 3.2通过Microsoft的情感API分析视频 我遇到以下错误: b'{“error”:{“code”:“Unauthorized”,“message”:“由于订阅密钥无效,访问被拒绝。请确保您订阅了试图调用的API并提供了正确的密钥。”}}” 我使用的是情感API订阅密钥(我还使用了Face API密钥和计算机视觉密钥以防万一) 代码:Python 3.x Microsoft情感视频API Python 3.2,python-3.x,image-recognition,face-recognition,microsoft-cognitive,Python 3.x,Image Recognition,Face Recognition,Microsoft Cognitive,我正在尝试使用Python 3.2通过Microsoft的情感API分析视频 我遇到以下错误: b'{“error”:{“code”:“Unauthorized”,“message”:“由于订阅密钥无效,访问被拒绝。请确保您订阅了试图调用的API并提供了正确的密钥。”}}” 我使用的是情感API订阅密钥(我还使用了Face API密钥和计算机视觉密钥以防万一) 代码: 你的代码可以工作。只需确保在生成API密钥后等待10分钟,以便它开始工作(Azure门户中这样说) 另外,一般来说,对于认知服务
你的代码可以工作。只需确保在生成API密钥后等待10分钟,以便它开始工作(Azure门户中这样说) 另外,一般来说,对于认知服务,请确保您拥有的API密钥对应于您试图访问的地区(美国西部等)
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))