python-3.x - 来自桶加密的 boto3 打印规则
问题描述
我正在编写一个 python 脚本来检索 AWS 的信息并且我试图只获取 SSEAlgorith 但我得到TypeError: list indices must be integers or slices, not str 有没有办法做到这一点?我想这是为了 [] 里面的规则。
{
"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']
推荐阅读
- python - SQLite3 未将字段值设置为指定值
- r - 在 R 中使用 igraph 创建具有复杂数据的图形
- javascript - 在 Vue 中何时使用 props 以及何时使用 $attrs
- python - 用矩阵逆模 N 扩展欧几里得算法
- python - Python 类为每次执行的@property 提供不同的输出
- arrays - 在不知道列长的情况下传递一个二维 int 数组的切片
- java - 如何将 FlowLayout 放在新行中?
- javascript - 仅消除双斜线和附加斜线并用一个斜线替换
- php - 当我使用 phpmailer 在同一个脚本上发送两封电子邮件时,第二封电子邮件会同时发送到第一个和第二个电子邮件地址
- reactjs - 如何修复我的反应应用程序中的 npm 启动错误?