简体   繁体   中英

botocore.exceptions.ClientError: An error occurred (404) when calling the HeadObject operation: Not Found

I'm downloading files from AWS S3 Bucket like so:

import boto3

s3client = boto3.client("s3")
s3 = boto3.resource('s3')

bucket_name = 'practice_bucket'
bucket = s3.Bucket(bucket_name)

for obj in bucket.objects.all():
    filename = obj.key.rsplit('/')[-1]
    s3client.download_file(bucket_name, obj.key, "/txt/" + filename)

When attempting to place some files under a subdirectory, eg /txt/ , I get the error:

botocore.exceptions.ClientError: An error occurred (404) when calling the HeadObject operation: Not Found

Oddly, it works on other file types using the same method, but doesn't work for ones with .json extension.

What could be the issue? I even tried without placing them in an absolute subdirectory path, and I get no error and downloads the file onto the same directory as the script downloading. But when I actually define the path to download the file to, I get the error.

Your code is correct.

botocore.exceptions.ClientError: An error occurred (404) when calling the HeadObject operation: Not Found

This error is thrown when the object you are trying to fetch is not present in the bucket.

升级 aiobotocore 为我解决了这个问题。

pip install --upgrade aiobotocore

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM