gpt4 book ai didi

python - Boto3 无效参数异常

转载 作者:太空狗 更新时间:2023-10-30 01:12:35 24 4
gpt4 key购买 nike

我有一些调用 AWS 的 Rekognition 服务的代码。有时它会抛出这个异常:

An error occurred (InvalidParameterException) when calling the DetectLabels operation: Request has Invalid Parameters

不过,我在文档或代码中的任何地方都找不到 InvalidParameterException,因此我无法为这种情况的发生编写特定的处理程序。有谁知道异常存在于哪个库模块中?

最佳答案

如果您在调用 search_faces_by_image 时看到此异常,则可能表明您提供的图像中没有可检测到的面孔。您可以在 API_SearchFacesByImage 查看可能的异常(exception)情况列表。 .

要处理这个异常,你可以这样写代码:

import boto3
rek = boto3.client('rekognition')

def lookup_faces(image, collection_id):
try:
faces = rek.search_faces_by_image(
CollectionId=collection_id,
Image=image,
FaceMatchThreshold=95
)
logger.info('faces detected: {}'.format(faces))
return faces
except rek.exceptions.InvalidParameterException as e:
logger.debug('no faces detected')
return None

关于python - Boto3 无效参数异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41863595/

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