我發現boto3的官方文檔(https://boto3.readthedocs.org/en/latest/reference/services/s3.html#S3.Bucket.create)與實際返回的內容之間令人沮喪的錯誤匹配。Python boto3 s3庫向官方文檔返回不同的字典
只是爲了確認,我使用的是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庫的一個包含的包裝,而我得到的dictionary中的RequestID
鍵最終來自botocore/parsers.py
。我明白了create
回報它實際上有更多的信息,但我不明白的是,put_object()
方法的返回不包含任何類似文件
我正在試圖找出是官方文件是否對我說謊。
爲什麼-1?至少證明它有道理。 – Mani
文檔沒有說謊,當沒有任何東西可以返回時,它們不會返回任何東西。沒有版本號,所以沒有版本號或刪除標記。沒有與請求一起發送的'RequestCharged',所以也沒有。 –
正確,所以+1簡潔模糊的文檔。 ;) – Mani