我发现 boto3 的官方文档(https://boto3.readthedocs.org/en/latest/reference/services/s3.html#S3.Bucket.create)与实际返回的内容之间存在令人沮丧的不匹配.
只是为了确保,我使用的是 boto3 1.2.1 和 botocore 1.3.2(都安装了 pip)。
我专门谈论使用以下boto3.Session
方法创建存储桶:
import boto3
session = boto3.Session(region_name = 'us-west-2', \
aws_access_key_id = 'AAA', \
aws_secret_access_key = 'BBB')
s3 = session.resource('s3')
bucket = s3.Bucket('testbucket').create()
我在文档中被告知该s3.Bucket('testbucket').create()
命令返回的字典看起来像
{
'Location': 'string'
}
但相反,我得到了一个看起来像这样的字典:
{
u'Location': '/testbucket',
'ResponseMetadata': {
'HTTPStatusCode': 200,
'HostId': 'alphnumericalmixed/alphanumericalmixed',
'RequestId': 'MIXEDUPPERANDNUMBERS123'
}
}
如果我尝试通过调用它的delete()
方法来删除一个 S3 对象,我也会得到类似的东西,例如:
# some initialisation as above code
obj=bucket.put_object(Body='123', Key='456')
print obj.delete()
我在哪里得到:
{'ResponseMetadata':
{'HTTPStatusCode': 204,
'HostId': 'something/something',
'RequestId': 'SOMETHING'}}
而不是(https://boto3.readthedocs.org/en/latest/reference/services/s3.html#S3.Object.delete):
{
'DeleteMarker': True|False,
'VersionId': 'string',
'RequestCharged': 'requester'
}
我知道 boto3 是 botocore 库的一个相关包装器,而RequestID
我要返回的字典中的键最终来自botocore/parsers.py
. 我理解create
return 因为它实际上有额外的信息,但我不明白的是put_object()
方法 return不包含任何类似于文档的内容
我正在努力解决的是官方文档是否对我撒谎。