Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 面API:未找到端点url的资源_Python - Fatal编程技术网

Python 面API:未找到端点url的资源

Python 面API:未找到端点url的资源,python,Python,我只是尝试运行MS的示例face API python代码。但我的代码无法从HTTPs获得响应。我编写了CollectAPI密钥和端点。 此端点-face\u api\u url仅响应 { "error": { "code": "ResourceNotFound", "message": "The requested resource was not found." } } 我该怎么办?请帮帮我 以下是我的源代码: subscription_key = 'I wrote my KEY' as

我只是尝试运行MS的示例face API python代码。但我的代码无法从HTTPs获得响应。我编写了CollectAPI密钥和端点。 此端点-
face\u api\u 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)

快速的谷歌搜索和比较让我相信你在做。从外观上看,您的url是错误的,应该是:
https://westcentralus.api.cognitive.microsoft.com/face/v1.0
/detect


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

站点管理员可能已决定,对于未在其标题中显示其用户代理的客户端,站点应视为不存在

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)
这帮我解决了