google-cloud-python icon indicating copy to clipboard operation
google-cloud-python copied to clipboard

gcloud.storage.get_bucket throws AttributeError 'api_rquest

Open charlesbclifford opened this issue 11 years ago • 3 comments

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.

charlesbclifford avatar May 15 '15 14:05 charlesbclifford

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.

dhermes avatar May 15 '15 14:05 dhermes

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

charlesbclifford avatar May 15 '15 14:05 charlesbclifford

No worries. Thanks for reaching out.

dhermes avatar May 15 '15 14:05 dhermes