Ale*_*don 4 amazon-s3 amazon-web-services python-3.x boto3
我正在编写一个可以从 Glacier 恢复对象的代码。我们将使用的层是标准层。我正在关注这个文档:
client.restor_object 上的 Bot3 文档
另请参阅 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}')
Run Code Online (Sandbox Code Playgroud)
这是回溯:
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
Run Code Online (Sandbox Code Playgroud)
文档显示:
response = client.restore_object(
Bucket='string',
Key='string',
VersionId='string',
RestoreRequest={
'Days': 123,
'GlacierJobParameters': {
'Tier': 'Standard'|'Bulk'|'Expedited'
},
...
Run Code Online (Sandbox Code Playgroud)
因此,您应该使用:
resp = bucket.meta.client.restore_object(
Bucket=obj_sum.bucket_name,
Key=obj_sum.key,
RestoreRequest={'Days': 1, 'GlacierJobParameters': {'Tier': 'Standard'}}
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4781 次 |
| 最近记录: |