-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
Describe the issue
The docs say:
Parsing for error responses uses the same exact methodology outlined in the low-level client section. Catching exceptions through the client’s exceptions property is slightly different, as you’ll need to access the client’s meta property to get to the exceptions.
client.meta.client.exceptions.SomeServiceExceptionUsing Amazon S3 as an example resource service, you can use the client’s exception property to catch the BucketAlreadyExists exception. And you can still parse the error response to get the bucket name that’s passed in the original request.
import botocore import boto3 client = boto3.resource('s3') try: client.create_bucket(BucketName='amzn-s3-demo-bucket') except client.meta.client.exceptions.BucketAlreadyExists as err: print("Bucket {} already exists!".format(err.response['Error']['BucketName'])) raise err
This works for S3 client. But not for SES client:
In [26]: ses = boto3.client("ses")
In [27]: ses.meta.client.exceptions
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[27], line 1
----> 1 ses.meta.client.exceptions
AttributeError: 'ClientMeta' object has no attribute 'client'
For SES client I can do:
In [28]: ses.exceptions
Out[28]: <botocore.errorfactory.SESExceptions at 0x125410fd0>
But that doesn't work for S3:
In [30]: client = boto3.resource('s3')
...:
In [32]: client.exceptions
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[32], line 1
----> 1 client.exceptions
AttributeError: 's3.ServiceResource' object has no attribute 'exceptions'
So it seems that the different clients are inconsistent, and the docs need to reflect this.
Links
https://boto3.amazonaws.com/v1/documentation/api/latest/guide/error-handling.html
I'm using boto3==1.38.17
on Python 3.11