首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >aws s3 -对象没有属性“server_side_encryption”

aws s3 -对象没有属性“server_side_encryption”
EN

Stack Overflow用户
提问于 2017-08-20 23:26:05
回答 2查看 1.5K关注 0票数 0

有人能解释一下这两个电话的区别吗。第一个给出正确的server_side_encryption,第二个给出一个错误。其他属性给出相同的值-

代码语言:javascript
运行
复制
#!/usr/bin/python

import boto3
import botocore

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


object = s3.Object('abcdefhkjl9999','error.html')

print(object.bucket_name)
print(object.key)
print(object.last_modified)
print(object.storage_class)
print(object.server_side_encryption)


bucket = s3.Bucket('abcdefhkjl9999')
for object in bucket.objects.all():
    print("#############################")
    print(object.bucket_name)
    print(object.key)
    print(object.last_modified)
    print(object.storage_class)
    print(object.server_side_encryption)


The output is -
abcdefhkjl9999
error.html
2017-08-20 22:58:02+00:00
REDUCED_REDUNDANCY
aws:kms
#############################
abcdefhkjl9999
error.html
2017-08-20 22:58:02+00:00
REDUCED_REDUNDANCY
Traceback (most recent call last):
File "./test3.py", line 26, in <module>
print(object.server_side_encryption)
AttributeError: 's3.ObjectSummary' object has no attribute       'server_side_encryption'
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-08-20 23:58:31

由于您收到的错误状态,您试图从其中获取server_side_encryption属性的对象实际上不是s3.Object类型的对象,而是s3.ObjectSummary类型的对象

幸运的是,您可以将对象作为子资源获得为在此指定

然后inner = outer.Object()查询该属性

print(inner.server_side_encryption)

票数 4
EN

Stack Overflow用户

发布于 2017-08-21 00:05:44

s3.Object返回对象

bucket.objects返回ObjectSummary

对象具有以下属性

代码语言:javascript
运行
复制
[u'Acl', u'Bucket', u'MultipartUpload', u'Version', u'accept_ranges', u'bucket_name', u'cache_control', u'content_disposition', u'content_encoding', u'content_language', u'content_length', u'content_type', 'copy', u'copy_from', u'delete', u'delete_marker', 'download_file', 'download_fileobj', u'e_tag', u'expiration', u'expires', u'get', 'get_available_subresources', u'initiate_multipart_upload', u'key', u'last_modified', 'load', 'meta', u'metadata', u'missing_meta', u'parts_count', u'put', 'reload', u'replication_status', u'request_charged', u'restore', u'restore_object', u'server_side_encryption', u'sse_customer_algorithm', u'sse_customer_key_md5', u'ssekms_key_id', u'storage_class', 'upload_file', 'upload_fileobj', u'version_id', u'wait_until_exists', u'wait_until_not_exists', u'website_redirect_location']

ObjectSummary具有以下属性

代码语言:javascript
运行
复制
[u'Acl', u'Bucket', u'MultipartUpload', u'Object', u'Version', u'bucket_name', u'copy_from', u'delete', u'e_tag', u'get', 'get_available_subresources', u'initiate_multipart_upload', u'key', u'last_modified', 'load', 'meta', u'owner', u'put', u'restore_object', u'size', u'storage_class', u'wait_until_exists', u'wait_until_not_exists']
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45787642

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档