gcloud.storage.get_bucket throws AttributeError 'api_rquest
I'm testing out the installation of gcloud-python on a new installation of Fedora 22. When, in the Python shell, I run the following script, the 'api_request' AttributeError is thrown.
$ python
Python 2.7.8 (default, Apr 15 2015, 09:26:43)
[GCC 4.9.2 20150212 (Red Hat 4.9.2-6)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gcloud
>>> from gcloud import storage
>>> storage.set_default_bucket("ccb_ci_acct")
>>> storage.set_default_project('applied-algebra-93003')
>>> storage_conn = storage.get_connection()
>>>
>>> storage.set_default_connection(storage_conn)
>>> bucket=storage.get_bucket("ccb_ci_acct","applied-algebra-93003")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/gcloud/storage/api.py", line 165, in get_bucket
bucket.reload()
File "/usr/lib/python2.7/site-packages/gcloud/storage/_helpers.py", line 57, in reload
self._properties = self.connection.api_request(
AttributeError: 'str' object has no attribute 'api_request'
>>>
My guess is that some mandatory configuration parameter is not being set (or being set properly). Any suggestions to resolve this problem are appreciated.
Pro tip: wrap your code snippets with three backticks (```). I have edited your snippet with this.
Note your error says that a str object can't make an api_request. This is because you are using storage.get_bucket incorrectly.
>>> from gcloud import storage
>>> help(storage.get_bucket)
Help on function get_bucket in module gcloud.storage.api:
get_bucket(bucket_name, connection=None)
Get a bucket by name.
...
By passing
storage.get_bucket("ccb_ci_acct","applied-algebra-93003")
you are sending the string "applied-algebra-93003" as the connection, which won't work.
Since you already called
storage.set_default_connection(storage_conn)
you can just call get_bucket with the bucket name and not worry about the connection.
Wow, that's the type of code I write at 2am. Sorry about taking your time on this issue. I apologize. I have to get some sleep.
On Fri, May 15, 2015 at 8:22 AM, Danny Hermes [email protected] wrote:
Pro tip: wrap your code snippets with three backticks (`).
Note your error says that a str object can't make an api_request. This is because you are using storage.get_bucket incorrectly.
from gcloud import storage>>> help(storage.get_bucket) Help on function get_bucket in module gcloud.storage.api:
get_bucket(bucket_name, connection=None) Get a bucket by name.
...
By passing
storage.get_bucket("ccb_ci_acct","applied-algebra-93003")
you are sending the string "applied-algebra-93003" as the connection, which won't work.
Since you already called
storage.set_default_connection(storage_conn)
you can just call get_bucket with the bucket name and not worry about the connection.
— Reply to this email directly or view it on GitHub https://github.com/GoogleCloudPlatform/gcloud-python/issues/884#issuecomment-102412375 .
Charles B. Clifford (720) 842-7251
No worries. Thanks for reaching out.