FACE API:找不到端点URL的资源

时间:2018-05-17 08:19:45

标签: python

我只是试图运行MS的示例面部API python代码。但我的代码无法从HTTPs获得响应。我写了我的收集api密钥和终点。 此结束点 - face_api_url仅响应

{ "error": { "code": "ResourceNotFound", "message": "The requested
 resource was not found." } }

我该怎么办?请帮帮我!!

这是我的源代码:

subscription_key = 'I wrote my KEY'
assert subscription_key
face_api_url = 'https://westcentralus.api.cognitive.microsoft.com/face/v1.0'


image_url = 'https://how-old.net/Images/faces2/main007.jpg'


import requests
from IPython.display import HTML

headers = { 'Ocp-Apim-Subscription-Key': subscription_key }

params = {
    'returnFaceId': 'true',
    'returnFaceLandmarks': 'false',
    'returnFaceAttributes': 'age,gender,headPose,smile,facialHair,glasses,emotion,hair,makeup,occlusion,accessories,blur,exposure,noise',
}

response = requests.post(face_api_url, params=params, headers=headers, json={"url": image_url})
faces = response.json()

print(faces)

2 个答案:

答案 0 :(得分:2)

快速谷歌搜索和比较让我相信你正在做this tutorial here。从它的外观来看,你有错误的网址(根据该教程)应该是:https://westcentralus.api.cognitive.microsoft.com/face/v1.0 / detect

(添加粗体以突出显示缺少的路径)

答案 1 :(得分:0)

对于没有在其标头中显示其User-Agent的客户端,站点管理员可能已决定该站点应表现为好像它不存在。

headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/75.0.3770.100 Safari/537.36',
           'Content-Type': 'application/octet-stream',
           'Ocp-Apim-Subscription-Key': subscription_key}

response = requests.post(face_api_url, params=params, headers=headers, data=image_data)
response.raise_for_status()
faces = response.json()
print(faces)

这为我解决了!