s3 head_object returns ClientError 404 instead of NoSuchKey error
See original GitHub issueWhat issue did you see ?
When the key does not exist in s3, s3 head_object returns a ClientError 404 instead of NoSuchKey error, making it harder to catch. Also, the doc says it should throw a NoSuchKey error. But get_object returns NoSuchKey.
Steps to reproduce
client.head_object(
Bucket=bucket,
Key=key,
) # throws ClientError with code 404
client.get_object(
Bucket=bucket,
Key=key,
) # throws NoSuchKey
Is this expected? If so, should the docs be modified? Thanks.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:20
- Comments:7 (2 by maintainers)
Top Results From Across the Web
s3 HeadObject returning object metadata but boto3 Copy ...
According to AWS documentation and stack overflow community, the best way to deal with 404 (NoSuchKey) error for read after right is to...
Read more >Downloading a File from an S3 Bucket - Amazon AWS
If the service returns a 404 error, it prints an error message indicating that the object doesn't exist. import boto3 import botocore BUCKET_NAME...
Read more >AWS S3 Error executing "HeadObject" / AWS HTTP error
Hello, I want use S3, but i have some problems in localhost I started with an arror where i need ... But you're...
Read more >Middleware — Swift 2.31.0.dev103 documentation
The s3api middleware will emulate the S3 REST api on top of swift. ... or the symlink creation will return a client error....
Read more >IBM Cloud Object Storage S3 API
This operation returns a list of all buckets within a service instance. ... with an incorrect location will result in a 404 NoSuchKey...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
As a temporary workaround (implying the bug will get fixed one day) you can catch the ClientError like this:
That way your code will still work as expected in case the bug gets fixed.
Checking in - I believe the docs have been updated since this original issue was opened. In the head_object and get_object boto3 docs it now says:
If that still doesn’t clarify the behavior then any further requests for improvements to the documentation should be redirected to the S3 team because they own their API documentation as mentioned here earlier.
There is a Provide feedback link at the bottom of every API page where you can send direct feedback to the appropriate team. Alternatively you can reach out through AWS Support or we can forward requests internally. Please let us know if you had any follow up questions on this.