kya*_*agu 6 amazon-s3 amazon-web-services boto3
我有以下一段代码,它利用 boto3 中的 list_objects_v2 。我收到错误 => keyError :“内容”。我假设如果我传递的文件名不存在,则会抛出此错误。
import boto3
s3_R = boto3.client('s3')
s3_b = s3_R.Bucket("MyBucket")
response = s3_R.list_objects_v2(Bucket=s3_b, Prefix='myfilename')
for obj in response['contents']:
file = obj['key']
print(file)
Run Code Online (Sandbox Code Playgroud)
假设返回一些对象,它应该是,Contents而不是:contents
response = s3_R.list_objects_v2(Bucket='MyBucket', Prefix='myfilename')
if 'Contents' in response:
for obj in response['Contents']:
file = obj['Key']
print(file)
else:
print("No objects returned")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8894 次 |
| 最近记录: |