You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
File "/path/to/some/venv/lib/python3.11/site-packages/botocore/client.py", line 915, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.errorfactory.NoSuchBucket: An error occurred (NoSuchBucket) when calling the PutObject operation: The specified bucket does not exist
But when updating the code to try and catch that the interpreter doesn't know what botocore.errorfactory.NoSuchBucket is
File "/path/to/my/script.py", line 400, in update_s3_files
except botocore.errorfactory.NoSuchBucket:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'botocore.errorfactory' has no attribute 'NoSuchBucket'
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.
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
The text was updated successfully, but these errors were encountered:
Thanks for reaching out and your patience here. The recommended approach is to catch the ClientError exception raised by Boto3 and check the error code within the exception. The Boto3 documentation on error handling service exceptions provides more context. Here's an example:
importboto3frombotocore.exceptionsimportClientErrors3=boto3.client('s3')
try:
response=s3.get_bucket_location(Bucket='nonexistent-bucket')
exceptClientErrorase:
ife.response['Error']['Code'] =='NoSuchBucket':
print('The specified bucket does not exist.')
else:
raisee
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.
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
The text was updated successfully, but these errors were encountered: