简体   繁体   English

botocore.exceptions.ClientError: 调用 HeadObject 操作时发生错误 (404):未找到

[英]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.

相关问题 Collectstatic 失败 - botocore.exceptions.ClientError:调用 HeadObject 操作时发生错误 (404):未找到 - Collectstatic failing - botocore.exceptions.ClientError: An error occurred (404) when calling the HeadObject operation: Not Found botocore.exceptions.ClientError:调用 HeadObject 操作时发生错误 (403):在 AWS SageMaker 中使用本地模式时禁止 - botocore.exceptions.ClientError: An error occurred (403) when calling the HeadObject operation: Forbidden while using local mode in AWS SageMaker 上传图片时出错。 botocore.exceptions.ClientError: 调用 PutObject 操作时发生错误 (AccessDenied) - Error when uploading images. botocore.exceptions.ClientError: An error occurred (AccessDenied) when calling the PutObject operation botocore.exceptions.ClientError:调用PutObject操作时发生错误(AccessDenied):访问被拒绝 - botocore.exceptions.ClientError: An error occurred (AccessDenied) when calling the PutObject operation: Access Denied botocore.exceptions.ClientError:调用GetItem操作时发生错误(InvalidSignatureException) - botocore.exceptions.ClientError: An error occurred (InvalidSignatureException) when calling the GetItem operation botocore.exceptions.ClientError调用GetObject操作时发生错误(SignatureDoesNotMatch) - botocore.exceptions.ClientError An error occurred (SignatureDoesNotMatch) when calling the GetObject operation 如何解决“botocore.exceptions.ClientError:发生错误(AccessDenied)”错误? - How to resolve the “botocore.exceptions.ClientError: An error occurred (AccessDenied)” error? AWS lambda:调用 HeadObject 操作时发生错误(404):未找到 - AWS lambda:An error occurred (404) when calling the HeadObject operation: Not Found AWS BOTO3 S3 python - 调用 HeadObject 操作时发生错误 (404):未找到 - AWS BOTO3 S3 python - An error occurred (404) when calling the HeadObject operation: Not Found ClientError: 调用 HeadObject 操作时发生错误 (403):尝试跨账户复制时禁止 - ClientError: An error occurred (403) when calling the HeadObject operation: Forbidden when trying cross account copy
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM