Replies: 1 comment
-
Thanks for reaching out and your patience here. The recommended approach is to catch the import boto3
from botocore.exceptions import ClientError
s3 = boto3.client('s3')
try:
response = s3.get_bucket_location(Bucket='nonexistent-bucket')
except ClientError as e:
if e.response['Error']['Code'] == 'NoSuchBucket':
print('The specified bucket does not exist.')
else:
raise e I also see that the version of Boto3 you're using is quite old, please consider updating to a newer version for access to the latest updates. (The latest version is 1.34.107 per the CHANGELOG). If you have any follow up questions please let us know. I'm going to convert this from an issue to a discussion as it is not a bug. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Describe the bug
When boto3 throws an exception and we attempt to catch it, it fails because the exception does not actually exist.
Was there a reason this issue #1195 closed? The problem persists.
Expected Behavior
The reported errror indicates an exception which can actually be caught
Current Behavior
When running the first two code snippets the interpreter throws a trace which includes the error
botocore.errorfactory.NoSuchBucket
But when updating the code to try and catch that the interpreter doesn't know what botocore.errorfactory.NoSuchBucket is
Reproduction Steps
Run the following code:
Because that bucket doesn't exist, boto3 throws a
botocore.errorfactory.NoSuchBucket
error.Add botocore and copy and paste
botocore.errorfactory.NoSuchBucket
into an except block and run it.Possible Solution
The current workaround to the try/except block is to catch
client.exceptions.NoSuchBucket
Which isn't a very usable solution since there is nothing in the error message to tell you what to do.
Proposed solutions:
Return the error in a way that indicates that we should be using the client.
b3_client.errorfactory.NoSuchBucket: An error occurred (NoSuchBucket) when calling the PutObject operation: The specified bucket does not exist
Update boto3 so that there is are accessible error objects such as
boto3.errors.NoSuchBucket
and return that in the error message.Update botocore so that the error exists.
Additionally code using boto3.resource() throws the same error.
Additional Information/Context
All of the code examples throw the same errors if boto3.session is not used. They include that to simplify testing in environments which use SSO with aws.
SDK version used
boto3==1.24.13 botocore==1.27.13
Environment details (OS name and version, etc.)
MacOS 14.2.1
Beta Was this translation helpful? Give feedback.
All reactions