首页 > 解决方案 > 为 boto 脚本提供的 XML 格式不正确

问题描述

我正在开发一个启用 S3 存储桶跨区域复制的 boto 脚本,我的脚本遵循了这个“https://stackoverflow.com/a/57778885/9931092”答案,该脚本似乎对我来说很好,但它没有ExistingObjectReplication作为代码的一部分,并且在添加时不会使代码运行。这是我的 boto 脚本:

import boto3
s3_client = boto3.client('s3')

response = s3_client.put_bucket_versioning(
    Bucket='cross-test-6',
    VersioningConfiguration={
        'Status': 'Enabled'
    },
)

response = s3_client.put_bucket_versioning(
    Bucket='cross-test-7',
    VersioningConfiguration={
        'Status': 'Enabled'
    },
)



##Enable
s3_client.put_bucket_replication(Bucket='cross-test-6', 
ReplicationConfiguration={
    "Role": "arn:aws:iam::196687784845:role/test",
    "Rules": [
        {
            "Status": "Enabled",
            "Priority": 1, 
            "DeleteMarkerReplication": { "Status": "Disabled" },
            "ExistingObjectReplication": { "Status": "Enabled" },
            "Filter" : { "Prefix": ""},            
            "Destination": {
                "Bucket": "arn:aws:s3:::cross-test-7",
                "Account": "196687784845"
            },           
        }
    ]
}
)

这是我得到的回溯:

Traceback (most recent call last):
  File "/home/pranay/Desktop/Amit/main-2.py", line 21, in <module>
    s3_client.put_bucket_replication(Bucket='cross-test-6', 
  File "/home/pranay/.local/lib/python3.8/site-packages/botocore/client.py", line 337, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/home/pranay/.local/lib/python3.8/site-packages/botocore/client.py", line 656, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (MalformedXML) when calling the PutBucketReplication operation: The XML you provided was not well-formed or did not validate against our published schema

我怀疑官方文档有'ExistingObjectReplication'而不是 "ExistingObjectReplication",尽管我也尝试过并且得到了同样的错误。

标签: pythonamazon-web-servicesamazon-s3boto3

解决方案


推荐阅读