requests.exceptions.HTTPError: 404 Client Error: Resource Not Found for url | Azure Cognitive Services Api

requests.exceptions.HTTPError: 404 Client Error: Resource Not Found for url | Azure Cognitive Services Api

我正在尝试通过 A​​zure 认知服务 API 发送图像。我收到此错误消息: requests.exceptions.HTTPError:404 客户端错误:找不到 url 的资源:https://myfirstpythonapi.cognitiveservices.azure.com/analyze? ...

# Use the requests library to simplify making a REST API call from Python 
import requests

# We will need the json library to read the data passed back 
# by the web service
import json

# You need to update the SUBSCRIPTION_KEY to 
# they key for your Computer Vision Service
SUBSCRIPTION_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

# You need to update the vision_service_address to the address of
# your Computer Vision Service
vision_service_address = "https://myfirstpythonapi.cognitiveservices.azure.com/"

# Add the name of the function you want to call to the address
address = vision_service_address + "analyze"

# According to the documentation for the analyze image function 
# There are three optional parameters: language, details & visualFeatures
parameters  = {'visualFeatures':'Description',
               'language':'en'}

# Open the image file to get a file object containing the image to analyze
image_path = "c:/Users/PC[enter image description here][1]T/Desktop/CallApi/Dodge.jpg"
image_data = open(image_path, "rb").read()

# According to the documentation for the analyze image function
# we need to specify the subscription key and the content type
# in the HTTP header. Content-Type is application/octet-stream when you pass in a image directly
headers    = {'Content-Type': 'application/octet-stream',
              'Ocp-Apim-Subscription-Key': SUBSCRIPTION_KEY}

# According to the documentation for the analyze image function
# we use HTTP POST to call this function
response = requests.post(address, headers=headers, params=parameters, data=image_data)

# Raise an exception if the call returns an error code
response.raise_for_status()

# Display the JSON results returned
results = response.json()
print(json.dumps(results))

请帮帮我。我是菜鸟...

你应该改变你的vision_service_address

如下所示,

vision_service_address = "https://<your_region>.api.cognitive.microsoft.com/vision/v3.2/"

测试结果:

修改后的代码:

# Use the requests library to simplify making a REST API call from Python 

import requests

# We will need the json library to read the data passed back 
# by the web service
import json

# You need to update the SUBSCRIPTION_KEY to 
# they key for your Computer Vision Service
SUBSCRIPTION_KEY = "03****e"

# You need to update the vision_service_address to the address of
# your Computer Vision Service
vision_service_address = "https://centralus.api.cognitive.microsoft.com/vision/v3.2/"

# Add the name of the function you want to call to the address
address = vision_service_address + "analyze"

# According to the documentation for the analyze image function 
# There are three optional parameters: language, details & visualFeatures
parameters  = {'visualFeatures':'Description',
               'language':'en'}

# Open the image file to get a file object containing the image to analyze
image_path = "E:\MyCase\Dev\Python\faceapi2\jason.jpg"
image_data = open(image_path, "rb").read()

# According to the documentation for the analyze image function
# we need to specify the subscription key and the content type
# in the HTTP header. Content-Type is application/octet-stream when you pass in a image directly
headers    = {'Content-Type': 'application/octet-stream',
              'Ocp-Apim-Subscription-Key': SUBSCRIPTION_KEY}

# According to the documentation for the analyze image function
# we use HTTP POST to call this function
response = requests.post(address, headers=headers, params=parameters, data=image_data)

# Raise an exception if the call returns an error code
response.raise_for_status()

# Display the JSON results returned
results = response.json()
print(json.dumps(results))