gpt4 book ai didi

python-3.x - 将 GLACIER 对象恢复到 S3 标准层

转载 作者:行者123 更新时间:2023-12-04 14:10:30 27 4
gpt4 key购买 nike

我正在编写一个可以从 Glacier 恢复对象的代码。我们将使用的层级是标准。
我正在关注这个文档:
Bot3 documentation on client.restor_object
另请参阅来自 github 帐户的此示例:https://github.com/boto/boto3/issues/380
此代码在没有RestoreRequest 中的Tier 选项的情况下工作。

 import boto3

s3 = boto3.resource('s3')
bucket = s3.Bucket('datasets-imported-imdb')
for obj_sum in bucket.objects.all():
if obj_sum.key == 'testfile.mov':
print(f'file being restored {obj_sum.key}')
resp = bucket.meta.client.restore_object(
Bucket=obj_sum.bucket_name,
Key=obj_sum.key,
RestoreRequest={'Days': 1,'Tier': 'Standard'}
)
else:
print(f'file not being restored {obj_sum.key}')
这是回溯:
Traceback (most recent call last):
File "test.py", line 8, in <module>
resp = bucket.meta.client.restore_object(
File "/home/alex_anadon/.local/lib/python3.8/site-packages/botocore/client.py", line 357, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/home/alex_anadon/.local/lib/python3.8/site-packages/botocore/client.py", line 676, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (MalformedXML) when calling the RestoreObject operation: The XML you provided was not well-formed or did not validate against our published schema

最佳答案

文档显示:

response = client.restore_object(
Bucket='string',
Key='string',
VersionId='string',
RestoreRequest={
'Days': 123,
'GlacierJobParameters': {
'Tier': 'Standard'|'Bulk'|'Expedited'
},
...
因此,您应该使用:
        resp = bucket.meta.client.restore_object(
Bucket=obj_sum.bucket_name,
Key=obj_sum.key,
RestoreRequest={'Days': 1, 'GlacierJobParameters': {'Tier': 'Standard'}}
)

关于python-3.x - 将 GLACIER 对象恢复到 S3 标准层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64755906/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com