Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datastore API, 'Forbidden: 403 Request had insufficient authentication scopes.' #3415

Closed
FilipeAleixo opened this issue May 13, 2017 · 2 comments
Assignees
Labels
api: datastore Issues related to the Datastore API. auth

Comments

@FilipeAleixo
Copy link

FilipeAleixo commented May 13, 2017

I'm running a TensorFlow model on Google ML Engine. When the model training is finished, I want to store a JSON string with the results to Datastore. For this, I am using the following:

from gcloud import datastore

def put_json_into_datastore(json_str, project_id, entity_type):
    """
    Store json string in Datastore
    """
    # Instantiate the client to the project
    datastore_client = datastore.Client(project_id)
    # The name/ID for the new entity
    name = str(datetime.datetime.now())
    # The Cloud Datastore key for the new entity
    entity_key = datastore_client.key(entity_type, name)
    # Prepare the new entity
    entity = datastore.Entity(key=entity_key)
    # Get the json string into the entity
    entity.update(json_str)
    # Put the entity into Datastore
    datastore_client.put(entity)

Although, I am getting the error 'Forbidden: 403 Request had insufficient authentication scopes.' Here's the full error trace:

Traceback (most recent call last): File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main "main", fname, loader, pkg_name) File "/usr/lib/python2.7/runpy.py", line 72, in _run_code exec code in run_globals File "/root/.local/lib/python2.7/site-packages/trainer/train.py", line 243, in FLAGS.entity_type) File "/root/.local/lib/python2.7/site-packages/trainer/data_helpers.py", line 253, in put_json_into_datastore datastore_client.put(entity) File "/usr/local/lib/python2.7/dist-packages/gcloud/datastore/client.py", line 329, in put self.put_multi(entities=[entity]) File "/usr/local/lib/python2.7/dist-packages/gcloud/datastore/client.py", line 355, in put_multi current.commit() File "/usr/local/lib/python2.7/dist-packages/gcloud/datastore/batch.py", line 260, in commit self._commit() File "/usr/local/lib/python2.7/dist-packages/gcloud/datastore/batch.py", line 243, in _commit self.project, self._commit_request, self._id) File "/usr/local/lib/python2.7/dist-packages/gcloud/datastore/connection.py", line 342, in commit _datastore_pb2.CommitResponse) File "/usr/local/lib/python2.7/dist-packages/gcloud/datastore/connection.py", line 124, in _rpc data=request_pb.SerializeToString()) File "/usr/local/lib/python2.7/dist-packages/gcloud/datastore/connection.py", line 98, in _request raise make_exception(headers, error_status.message, use_json=False) Forbidden: 403 Request had insufficient authentication scopes.

Do I need to grant access somewhere for the ML engine to access the Datastore API?

@dhermes
Copy link
Contributor

dhermes commented Jun 5, 2017

@FilipeAleixo Sorry for the delay. First, I'd like to suggest you upgrade from gcloud to google-cloud-datastore. (The latest gcloud release was in September 2016.)

Second, our Client-s should provide the correct scopes, sometimes a 403 occurs when the API hasn't been turned on / enabled in the Cloud Console for your project.

@dhermes dhermes added api: datastore Issues related to the Datastore API. auth labels Jun 5, 2017
@dhermes dhermes changed the title Google ML Engine and Python Datastore API, 'Forbidden: 403 Request had insufficient authentication scopes.' Datastore API, 'Forbidden: 403 Request had insufficient authentication scopes.' Jun 5, 2017
@lukesneeringer
Copy link
Contributor

Thank you for filing this issue. We asked some clarifying questions a week or more ago and never heard back from you. We are unable to proceed with this issue until then, so we are closing it. Please feel free to re-open this issue with more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: datastore Issues related to the Datastore API. auth
Projects
None yet
Development

No branches or pull requests

3 participants