【发布时间】:2021-08-13 06:20:10
【问题描述】:
我尝试循环获取当前文件,例如ap-sounteast/2021/02/12,我得到了所有区域并输入了年、月、日但不工作
然后我尝试2021/ 并没有同样的原因
我的代码有什么问题?
year = now.strftime("%Y")
month = now.strftime("%m")
day = now.strftime("%d")
account = bucket.meta.client.list_objects(Bucket=bucket.name, Prefix='AWSLogs/', Delimiter='/')
for account in account.get('CommonPrefixes'):
list_account = account.get('Prefix')
region = bucket.meta.client.list_objects(Bucket=bucket.name, Prefix=(list_account+'CloudTrail/'), Delimiter='/')
for region in region.get('CommonPrefixes'):
region = region.get('Prefix')
files = bucket.meta.client.list_objects(Bucket=bucket.name, Prefix=(region+year+'/'+month+'/'+day+'/'), Delimiter='/')
for files in files.get('CommonPrefixes'):
files = files.get('Prefix')
print (files)
错误
9 files = bucket.meta.client.list_objects(Bucket=bucket.name, Prefix=(region+year+'/'+month+'/'+day+'/'), Delimiter='/')
---> 10 for files in files.get('CommonPrefixes'):
11 files = files.get('Prefix')
12 print (files)
TypeError: 'NoneType' object is not iterable
谢谢
【问题讨论】:
-
请edit您的问题并发布错误和回溯的全文。另外,请确保您的代码是独立的minimal reproducible example。
标签: python amazon-web-services amazon-s3 boto3