python-docs-samples icon indicating copy to clipboard operation
python-docs-samples copied to clipboard

PubSub client example: StatusCode.PERMISSION_DENIED

Open bluecmd opened this issue 10 years ago • 8 comments

In which file did you encounter the issue?

https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/pubsub/cloud-client/publisher.py

Did you change the file? If so, how?

Nope.

Describe the issue

$ python publisher.py list
Traceback (most recent call last):
  File "publisher.py", line 93, in <module>
    list_topics()
  File "publisher.py", line 33, in list_topics
    for topic in pubsub_client.list_topics():
  File "/usr/local/lib/python2.7/dist-packages/google/cloud/iterator.py", line 210, in _items_iter
    for page in self._page_iter(increment=False):
  File "/usr/local/lib/python2.7/dist-packages/google/cloud/iterator.py", line 239, in _page_iter
    page = self._next_page()
  File "/usr/local/lib/python2.7/dist-packages/google/cloud/iterator.py", line 437, in _next_page
    items = six.next(self._gax_page_iter)
  File "/usr/local/lib/python2.7/dist-packages/google/gax/__init__.py", line 435, in next
    return self.__next__()
    errors.create_error('RPC failed', cause=exception))
google.gax.errors.GaxError: GaxError(RPC failed, caused by <_Rendezvous of RPC that terminated with (StatusCode.PERMISSION_DENIED, User not authorized to perform this action.)>)

Running the pubsub.projects.topics.list api from https://developers.google.com/apis-explorer workst just fine.

I'm running this inside the Cloud Shell on a project with Cloud Pub/Sub API enabled and some topics set up. gcloud auth list shows my account, cloud auth login greatly discourages me to use it inside a Cloud Shell so I haven't tried refreshing my credentials.

bluecmd avatar Dec 03 '16 18:12 bluecmd

@bluecmd there may be something wonky with the cloud shell credentials.

@ryanmats can you take a look?

theacodes avatar Dec 05 '16 17:12 theacodes

@bluecmd Hi Christian! I just looked at your issue and it looks like you can resolve it by generating a service account key file in JSON (https://developers.google.com/identity/protocols/OAuth2ServiceAccount#creatinganaccount). Once this file is downloaded to your computer, move it to a desired location in the Cloud Shell and set the GOOGLE_APPLICATION_CREDENTIALS environment variable to the path to the key file, for example:

export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account.json

This information is in ~/python-docs-samples/pubsub/cloud-client/README.rst

Thanks, and happy holidays!

ryanmats avatar Dec 05 '16 19:12 ryanmats

@ryanmats Thanks, but surely that should Just Work(tm) on the cloud shell? "Once that file is downloaded to your computer" doesn't really work that well in Cloud Shell and is quite inconvenient.

bluecmd avatar Dec 05 '16 22:12 bluecmd

@bluecmd indeed. We're aware of this problem. It's due to a quirk in how cloud shell provides credentials. We've referenced this github issue on the internal bug, and we'll update if there's a resolution.

theacodes avatar Dec 05 '16 23:12 theacodes

@jonparrott Thanks!

bluecmd avatar Dec 05 '16 23:12 bluecmd

Any update here? Running into the same issue.

mritchie712 avatar Oct 21 '17 20:10 mritchie712

news about this error?

csantanaes avatar Jan 09 '18 20:01 csantanaes

You should use a service account as described here: https://cloud.google.com/docs/authentication/getting-started

theacodes avatar Jan 09 '18 20:01 theacodes