我正在检查 S3 存储桶中是否存在对象。以下是我正在使用的代码片段。 obj
是文件名。
s3 = boto3.resource('s3')
try:
s3.head_object(Bucket=bucket_name, Key=obj)
except ClientError as e:
return False
但它让我异常:
An exception occurred in python_code : 's3.ServiceResource' object has no attribute 'head_object'
我用于此 API 的参考 - https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.Client.head_object
谁能帮我解决这个问题?
原文由 gkr2d2 发布,翻译遵循 CC BY-SA 4.0 许可协议
尝试:
s3 = boto3.client('s3')
代替
boto3.resource('s3')