Boto3 InvalidParameterException

I have code that calls AWS Rekognition. Sometimes this throws this exception:

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

I cannot find InvalidParameterExceptionanywhere in the documentation or code, however, so I cannot write a specific handler when this happens. Does anyone know in which library module this exception lives?

+5
source share
4 answers

I found it in boto/cognito/identity/exceptions.py:

from boto.exception import BotoServerError

class InvalidParameterException(BotoServerError):
    pass
+3
source

This is an AWS error, this error occurs when the original image does not contain detectable faces. Make sure your original image has a recognizable face.

+1
source

Python3 boto3 :

from botocore.exceptions import ClientError

catch ClientError as e:
0

If you saw this exception in response to a call, search_faces_by_imageit probably means that there were no detectable faces in the image you provided. You can view a list of possible exceptions in the API_SearchFacesByImage .

To handle this exception, you can write code like this:

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
0
source

Source: https://habr.com/ru/post/1667825/


All Articles