我正在尝试使用Microsoft Azure情感API测试一些图像。按照microsoft上的说明,我一直得到{“statusCode”:404,“message”:“Resource not found”}错误。我的代码在网站上修改如下:
########### Python 2.7 #############
import httplib, urllib, base64
headers = {
# Request headers. Replace the placeholder key below with your subscription key.
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': 'key',
}
params = urllib.urlencode({ })
# Replace the example URL below with the URL of the image you want to analyze.
body = "{ 'url':'http://www.scientificamerican.com/sciam/cache/file/35391452-5457-431A-A75B859471FAB0B3.jpg' }"
try:
# NOTE: You must use the same region in your REST call as you used to obtain your subscription keys.
# For example, if you obtained your subscription keys from westcentralus, replace "westus" in the
# URL below with "westcentralus".
conn = httplib.HTTPSConnection('westcentralus.api.cognitive.microsoft.com')
conn.request("POST", "/emotion/v1.0/recognize?%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))
另外,当我在浏览器中输入端点url时,它显示{“error”:{“code”:“ResourceNotFound”,“message”:“resource notfound.”}。我不确定这是否与错误有关。在
有人遇到过这个问题吗?或者有人能给我一些解决问题的建议吗?谢谢!在
我试图成功地重现您的问题,这是由
westcentralus
主机不存在引起的,如下所示。在请在代码中将宿主
westcentralus.api.cognitive.microsoft.com
更改为westus.api.cognitive.microsoft.com
,然后它就可以工作了。在相关问题 更多 >
编程相关推荐