Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python s3 using boto, says 'attribute error: 'str' object has no attribute 'connection'

I have a connection that works as I can list buckets, but having issues when trying to add a object.

conn = S3Connection(awskey, awssecret)

key = Key(mybucket)

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

I get the error:

'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
like image 615
Blankman Avatar asked Aug 03 '10 00:08

Blankman


People also ask

What is S3 Boto3 resource (' S3 ')?

Amazon Simple Storage Service (Amazon S3) is an object storage service that offers scalability, data availability, security, and performance.

Does Boto3 use SSL?

The boto3 client includes a use_ssl parameter: use_ssl (boolean) -- Whether or not to use SSL. By default, SSL is used. Note that not all services support non-ssl connections.


1 Answers

Just replace:

key = Key(mybucket)

with:

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

Expanding on sth's comment, you can't pass a string, it needs to be a bucket object.

like image 108
Brian Avatar answered Nov 15 '22 06:11

Brian