【问题标题】:400 respone from Azure Computer Vision API来自 Azure 计算机视觉 API 的 400 响应
【发布时间】:2023-03-23 20:06:01
【问题描述】:

我对 Azure 上的计算机视觉资源有疑问。此代码基于文档示例,并且已经运行。(https://docs.microsoft.com/en-us/azure/cognitive-services/computer-vision/quickstarts/python-disk)

突然我开始收到 400 错误:

requests.exceptions.HTTPError: 400 Client Error: Bad Request for 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(看起来还可以)并创建了新资源 - 什么都没有。有什么想法吗?

【问题讨论】:

    标签: python azure computer-vision


    【解决方案1】:

    好像你生成的url是错误的,你可以试试下面的代码,

    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]
    

    【讨论】:

    • 试过你的代码(使用我的资源)。同样的回应:(
    【解决方案2】:

    某张照片有问题 - 下一张照片还可以

    【讨论】:

      猜你喜欢
      • 2020-05-24
      • 2018-08-12
      • 1970-01-01
      • 1970-01-01
      • 2020-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-07
      相关资源
      最近更新 更多