aws s3 - object has no attribute server_side_encryption

2024/10/14 3:19:46

Can someone please explain the differences in these two calls. The first one gives the correct server_side_encryption and the second one gives an error. The other attributes give the same value-

#!/usr/bin/pythonimport boto3
import botocores3 = 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'
Answer

As the error you received states, the object you're trying to get the server_side_encryption attribute from is not, in fact, of the type s3.Object, but rather of the type s3.ObjectSummary

Fortunately you can get the object as a sub-resource as specified here

inner = outer.Object() Then query for the property

print(inner.server_side_encryption)

https://en.xdnf.cn/q/118005.html

Related Q&A

Removing nested for loop to find coincidence values

I am currently using a nested for loop to iterate through to arrays to find values that match a certain criterion. The problem is that this method is incredibly inefficient and time consuming. I was to…

Combine two pandas DataFrame into one new

I have two Pandas DataFrames whose data from different sources, but both DataFrames have the same column names. When combined only one column will keep the name.Like this:speed_df = pd.DataFrame.from_d…

Reasons of slowness in numpy.dot() function and how to mitigate them if custom classes are used?

I am profiling a numpy dot product call. numpy.dot(pseudo,pseudo)pseudo is a numpy array of custom objects. Defined as:pseudo = numpy.array([[PseudoBinary(1), PseudoBinary(0), PseudoBinary(1)],[PseudoB…

How to open cmd and run ipconfig in python

I would like to write a script that do something like that: open the cmd and run the commend "ipconfig" and than copy my ip and paste it to a text file. I wrote the beginning of the script …

Using OAuth to authenticate Office 365/Graph users with Django

We are creating an application for use in our organization, but we only want people in our organization to be able to use the app. We had the idea of using Microsofts OAuth endpoint in order to authent…

Python flatten array inside numpy array

I have a pretty stupid question, but for some reason, I just cant figure out what to do. I have a multi-dimensional numpy array, that should have the following shape:(345138, 30, 300)However, it actual…

Peewee and Flask : Database object has no attribute commit_select

Im trying to use Peewee with Flask, but I dont understand why my database connection does not work.config.pyclass Configuration(object): DATABASE = {name: test,engine: peewee.MySQLDatabase,user: root,p…

for loop to create a matrix in python

I am trying to study the probability of having a zero value in my data and I have developed a code that outputs the value of a column of data when the other is zero which is what I need. But having to …

How to convert List of JSON frames to JSON frame

I want to convert List of JSON object ot Single JSON frameHere is my codefor i in user1:name=i.namepassword=i.passwordid1=i.iduser = { "name" : name,"password" : password,"id&q…

Python 2.7 The packaging package is required; normally this is bundled with this package

I expect this has to do with the cryptography module, but Im not sure.Traceback (most recent call last):File "<string>", line 11, in <module>File "c:\python27\lib\site-packag…