Boto3: AttributeError: 'S3' object has no attribute 'Bucket'

Created on 19 Aug 2017  路  3Comments  路  Source: boto/boto3

i am new to aws, when ever i am trying to download a file it is giving this error
I am using boto3
AttributeError: 'S3' object has no attribute 'Bucket'

below is my code snippet

try:
    s3.Bucket(bucketname).download_file(key,directory)
except botocore.exceptions.ClientError as e:
    if e.response['Error']['Code'] == "404":
        print("The object does not exist.")
closing-soon question

Most helpful comment

How are you creating the s3 object?
Because s3 = boto3.client('s3') does not have Bucket and s3 = boto3.resource('s3') does have bucket.

All 3 comments

How are you creating the s3 object?
Because s3 = boto3.client('s3') does not have Bucket and s3 = boto3.resource('s3') does have bucket.

I agree with @chenhe95 's suspicion. If you use the client interface to access the bucket:

boto3.client('s3').Bucket('mybucket')

you will get that error. Instead you need to be doing something like this:

boto3.resource('s3').Bucket('mybucket')

Let us know if that helps.

Closing due to inactivity

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tgal picture tgal  路  4Comments

leima965 picture leima965  路  3Comments

arnonki picture arnonki  路  3Comments

danielmorozoff picture danielmorozoff  路  3Comments

chesstrian picture chesstrian  路  3Comments