[英]botocore.exceptions.ClientError: An error occurred (404) when calling the HeadObject operation: Not Found
I'm downloading files from AWS S3 Bucket like so:我正在从 AWS S3 Bucket 下载文件,如下所示:
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:当试图将一些文件放在子目录下时,例如
/txt/
,我收到错误:
botocore.exceptions.ClientError: An error occurred (404) when calling the HeadObject operation: Not Found
botocore.exceptions.ClientError: 调用 HeadObject 操作时发生错误 (404):未找到
Oddly, it works on other file types using the same method, but doesn't work for ones with .json
extension.奇怪的是,它使用相同的方法处理其他文件类型,但不适用于扩展名为
.json
文件类型。
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
botocore.exceptions.ClientError: 调用 HeadObject 操作时发生错误 (404):未找到
This error is thrown when the object you are trying to fetch is not present in the bucket.当您尝试获取的对象不存在于存储桶中时,将引发此错误。
升级 aiobotocore 为我解决了这个问题。
pip install --upgrade aiobotocore
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.