codyc4321 codyc4321 - 1 year ago 77
Python Question

Forbidden: 403 User not authorized even though the user is logged in

I am getting 403 error on Mac trying to hit a URL that uses the Python client:

Traceback (most recent call last):
File "/Users/cchilders/.virtualenvs/myproject/lib/python2.7/site-packages/flask/", line 1639, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/cchilders/.virtualenvs/myproject/lib/python2.7/site-packages/flask/", line 1625, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/cchilders/work_projects/myproject/myproject/blueprints/", line 25, in health
File "/Users/cchilders/work_projects/myproject/myproject/views/", line 52, in read
if not topic.exists():
File "/Users/cchilders/.virtualenvs/myproject/lib/python2.7/site-packages/gcloud-0.18.3-py2.7.egg/gcloud/pubsub/", line 179, in exists
File "/Users/cchilders/.virtualenvs/myproject/lib/python2.7/site-packages/gcloud-0.18.3-py2.7.egg/gcloud/pubsub/", line 171, in topic_get
return conn.api_request(method='GET', path='/%s' % (topic_path,))
File "/Users/cchilders/.virtualenvs/ourapi/lib/python2.7/site-packages/gcloud-0.18.3-py2.7.egg/gcloud/", line 347, in api_request
error_info=method + ' ' + url)
Forbidden: 403 User not authorized to perform this action. (GET - - [10/Nov/2016 16:40:58] "GET /admin/health/ HTTP/1.1" 500 -


ps = pubsub.Client()
topic = ps.topic(application.config['PUBSUB_TOPIC'])
# topic.project = application.config['PUBSUB_PROJECT']
t_component = Component() = 'topic'
t_component.status = 'UP'
t_component.desc = ('{} exists and is healthy.'
if not topic.exists():
t_component.status = 'DOWN'
t_component.desc = (
'Configured PUBSUB topic ({}) does not exist.'

I created the topic/subscription so I have permissions. My config and gcloud user is correct, I did
gcloud auth ...
and double-checked. I'm the only one getting this error and I did have my personal account used on this laptop to practice the gcloud tutorial. My coworker thought using that other account in the past may cause an issue. I checked my config and the project I'm pointing to, it's the right project. Any help appreciated, thank you

Answer Source

There is a difference between gcloud auth login and gcloud auth application-default login

Re-logging in under gcloud auth application-default login fixed

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download