0

因此,我正在尝试按照此处的 microsoft face api 文档获取“FindSimilar”功能。在我使用此代码的页面底部有一个示例:

########### Python 3.2 #############
import http.client, urllib.request, urllib.parse, urllib.error, base64

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

params = urllib.parse.urlencode({
})

try:
    conn = http.client.HTTPSConnection('westus.api.cognitive.microsoft.com')
    conn.request("POST", "/face/v1.0/findsimilars?%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))

我收到一条错误消息,告诉我我的订阅密钥无效,但我检查了我的 azure 帐户状态,但没有发现任何问题:

b'\n\t\t\t\t\t{"error":{"code":"Unspecified","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."}}\n                \t\t'
4

1 回答 1

0

由于订阅密钥无效,访问被拒绝。确保您订阅了您尝试调用的 API 并提供正确的密钥。

它表明Invalid subscription Key or user/plan is blocked. 我建议您检查 APi Key

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

在此处输入图像描述

于 2018-04-18T07:16:27.787 回答