gpt4 book ai didi

python - 来自 Azure 计算机视觉 API 的 400 响应

转载 作者:太空宇宙 更新时间:2023-11-03 20:20:32 24 4
gpt4 key购买 nike

我在 Azure 上的计算机视觉资源方面遇到问题。该代码基于文档示例,并且已经有效。( https://learn.microsoft.com/en-us/azure/cognitive-services/computer-vision/quickstarts/python-disk )

突然我开始收到 400 错误:

requests.exceptions.HTTPError: 400 客户端错误: url 请求错误: https://nameofmyresource.cognitiveservices.azure.com/vision/v2.0/analyze?visualFeatures=Objects%2CTags

我的一段代码:

for img_path in img_path_list:
image_data = open(img_path, "rb").read()
print(image_data)
headers = {'Ocp-Apim-Subscription-Key': subscription_key,
'Content-Type': 'application/octet-stream'}
params = {'visualFeatures': 'Objects,Tags'}
response = requests.post(
analyze_url, headers=headers, params=params, data=image_data)
response.raise_for_status()
analysis = response.json()

我已经打印了 image_data (看起来不错)并创建了新资源 - 什么也没有。有什么想法吗?

最佳答案

看来您生成的网址是错误的,您可以尝试以下代码吗,

apikey = "e720e03190c41148ec555889daf2f64"
assert apikey
api_url = "https://southeastasia.api.cognitive.microsoft.com/vision/v2.0/"
analyse_api = api_url + "analyze"
image_data = img
headers = {"Ocp-Apim-Subscription-Key": apikey,
'Content-Type': 'application/octet-stream'}
params = {'visualFeatures':'Categories,Description,Color,Objects,Faces'}
response = requests.post(
analyse_api, headers=headers, params=params, data=image_data)
response.raise_for_status()
analysis = response.json()
#image_caption = analysis["description"]["captions"][0]["text"].capitalize()
people = 0
for i in analysis['objects']:
if i['object'] == 'person':
people += 1
describepeople = []
for i in analysis['faces']:
describepeople.append(i['gender'] + ' ' + str(i['age']))
tags = analysis['description']['tags']
return[people, describepeople, tags]

关于python - 来自 Azure 计算机视觉 API 的 400 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58190540/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com