question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

boto3.client("s3").head_bucket does not throw NoSuchBucket as per documentation

See original GitHub issue

Contrary to documentation, boto3.client(“s3”).head_bucket(Bucket=bucket_name) does not throw S3.Client.exceptions.NoSuchBucket. It throws An error occurred (404) when calling the HeadBucket operation: Not Found https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.Client.head_bucket

import boto3
client = boto3.client("s3")
try:
    client.head_bucket(Bucket='bucket-does-not-exist')
except client.exceptions.NoSuchBucket:
    print('exception caught')

The above code snippet should print ‘exception caught’. However, It throws the below exception.

  File "/Users/ashaik/.local/share/virtualenvs/loadenv38-el3BARCC/lib/python3.8/site-packages/botocore/client.py", line 316, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/Users/ashaik/.local/share/virtualenvs/loadenv38-el3BARCC/lib/python3.8/site-packages/botocore/client.py", line 635, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (404) when calling the HeadBucket operation: Not Found

Please align documentation and behavior of exception thrown.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
BastianZimcommented, Sep 15, 2021

Hi @stobrien89 ok thanks for looking into this again though!

0reactions
stobrien89commented, Sep 15, 2021

Hi again @BastianZim,

Had a chance to look into this further this morning and it looks like the documentation has been updated:

If the bucket does not exist or you do not have permission to access it, the HEAD request returns a generic 404 Not Found or 403 Forbidden code. A message body is not included, so you cannot determine the exception beyond these error codes.

From what I understand, they won’t be able to remove the error from the model, as it would be a breaking change, so it will remain listed under the exceptions section, which is derived from the s3 model. Wish there was more we could do here!

Read more comments on GitHub >

github_iconTop Results From Across the Web

S3 — Boto3 Docs 1.26.32 documentation - Amazon AWS
Parameters. Bucket (string) --. [REQUIRED]. The bucket name to which the upload was taking place. When using this action with an access point, ......
Read more >
Boto3 client upload_fileobj throws error NoSuchBucket
First thing to check is the region. If you installed the CLI, you probably have the credentials and the config in your home...
Read more >
s3 - Amazon Web Services - Go SDK - AWS Documentation
See the Amazon Simple Storage Service client S3 for more information on creating ... Code: NoSuchBucket Description: The specified bucket does not exist....
Read more >
Boto3 – Amazon S3 As Python Object Store
It can throw an “NoSuchKey” exception, if the key is not present. import boto3 import pickle #Connect to S3 s3 = boto3.client('s3') #Read...
Read more >
Handling Errors in Boto3 & Botocore - Trek10
It's a well-documented fact that saying "hah, no need to worry about X failing" is ... import boto3 import botocore.exceptions s3 = boto3.client('s3')...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found