close

[Solved] An exception occurred : ‘s3.ServiceResource’ object has no attribute ‘head_object’

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error An exception occurred : ‘s3.ServiceResource’ object has no attribute ‘head_object’ in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How An exception occurred : ‘s3.ServiceResource’ object has no attribute ‘head_object’ Error Occurs?

Today I get the following error An exception occurred : ‘s3.ServiceResource’ object has no attribute ‘head_object’ in python.

How To Solve An exception occurred : ‘s3.ServiceResource’ object has no attribute ‘head_object’ Error ?

  1. How To Solve An exception occurred : 's3.ServiceResource' object has no attribute 'head_object' Error ?

    To Solve An exception occurred : 's3.ServiceResource' object has no attribute 'head_object' Error Your requirement/operation requires an action on a bucket rather on a object/resource in the bucket.

  2. An exception occurred : 's3.ServiceResource' object has no attribute 'head_object'

    To Solve An exception occurred : 's3.ServiceResource' object has no attribute 'head_object' Error Your requirement/operation requires an action on a bucket rather on a object/resource in the bucket.

Solution 1

Try:

s3 = boto3.client('s3')

instead of

boto3.resource('s3')

Solution 2

I am bundeling a detailed response here:

1. boto3.client("s3") will allow you to perform Low level API calls
2. boto3.resource('s3') will allow you to perform High level API calls

Your requirement/operation requires an action on a bucket rather on a object/resource in the bucket. So here, it make sense and that is how AWS people have differentiated here API calls wrapper in the above mentined client methods

That is the reason why here boto3.client("s3") comes in picture.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read