首页 > 解决方案 > TypeError:预期的字符串或类似字节的对象 - Python (boto3)

问题描述

我正在尝试使用 boto3 和该put_bucket_encryption()函数在 S3 存储桶上启用加密。但是,我似乎收到以下错误:

[ERROR] TypeError: expected string or bytes-like object

特别是,它抱怨这条线:

'SSEAlgorithm': 'AES256'

下面是我的代码:

s3_client = boto3.client('s3', region_name='us-east-1')
s3_client.put_bucket_encryption(
  Bucket=bucket,
    ServerSideEncryptionConfiguration={
      'Rules':[
        {
           'ApplyServerSideEncryptionByDefault': {
              'SSEAlgorithm': 'AES256'
           }
         }
      ]   
   }
)

我尝试将整个对象转换为字符串以及它抱怨的行,但是无济于事。任何帮助表示赞赏。

标签: pythonamazon-web-servicesamazon-s3aws-lambdaboto3

解决方案


推荐阅读