2017-08-20 5 views
0

Quelqu'un peut-il expliquer s'il vous plaît les différences dans ces deux appels. Le premier donne le bon server_side_encryption et le second donne une erreur. Les autres attributs donnent le même forte valeur aws s3 - l'objet n'a pas d'attribut 'server_side_encryption'

#!/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' 

Répondre

3

Comme l'erreur que vous avez reçu les états, l'objet que vous essayez d'obtenir l'attribut server_side_encryption de n'est pas, en fait, du type s3.Object, mais plutôt du type s3.ObjectSummary

Heureusement, vous pouvez obtenir l'objet en tant que sous-ressources comme specified here

inner = outer.Object() interroger ensuite la propriété

print(inner.server_side_encryption)

2

s3.Object retours Object

bucket.objects retours ObjectSummary

objet a ces attributs

[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 a ces attributs

[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']