我正在编写一个python脚本来检索AWS的信息,我试图只获得SSEAlgorith,但我得到TypeError:列表索引必须是整数或切片,而不是str有什么办法可以做到吗?我猜是Rules里面的[]。
{
"ServerSideEncryptionConfiguration": {
"Rules": [
{
"ApplyServerSideEncryptionByDefault": {
"SSEAlgorithm": "AES256"
}
}
]
}
}
这是我用来检索信息的代码:
s3 = boto3.client('s3')
buc = s3.list_buckets()
for i in response['Buckets']:
enc = s3.get_bucket_encryption(Bucket=i['Name'])
rules = enc['ServerSideEncryptionConfiguration']['Rules']['ApplyServerSideEncryptionByDefault']['SSEAlgorithm']
print(rules)
Rules
是一个列表。所以假设你只有一个列表,它应该是:
rules = enc['ServerSideEncryptionConfiguration']['Rules'][0]['ApplyServerSideEncryptionByDefault']['SSEAlgorithm']