Python s3 using boto says: "Attribute error: str object does not have connection attribute

I have a connection that works, since I can list the buckets, but you have problems trying to add an object.

conn = S3Connection(awskey, awssecret)

key = Key(mybucket)

key.key = p.sku
key.set_contents_from_filename(fullpathtofile)

I get an error message:

'attribute error: 'str' object has no attribute 'connection'

the error is in the file:

/usr/local/lib/python2.6/dist-package/boto-2.obl-py2.6.egg/boto/s3/key.py' line # 539
+5
source share
4 answers

Keyexpects the conn.create_bucket()bucket to be the first parameter (possibly created ).

It mybucketdoes not seem to be a bucket, but a string, so the call fails.

+5
source

Just replace:

key = Key(mybucket)

with:

mybucket = "foo"
bucketobj = conn.get_bucket(mybucket)
mykey = Key(bucketobj)

sth, , bucket.

+13

:

import boto
s3 = boto.connect_s3()
bucket = s3.get_bucket("mybucketname")
key = bucket.new_key("mynewkeyname")
key.set_contents_from_filename('path_to_local_file', policy='public-read')

+6

import boto3

s3 = boto3.resource('s3')

mybucket = s3.Bucket('mybucketName')

Now you get the s3 bucket object. You received a string.

Enjoy it!

0
source

All Articles