Skip to content

Datastore: Client requires authentication even when connecting to the datastore emulator #11

Closed
@rylz

Description

@rylz

When I try to construct a datastore client on a box that has the datastore emulator enabled and running, I get the following:

  File ".../model/datastore.py", line 6, in <module>
    client = datastore.Client()
  File ".../lib/python3.6/site-packages/google/cloud/datastore/client.py", line 205, in __init__
    project=project, credentials=credentials, _http=_http)
  File ".../lib/python3.6/site-packages/google/cloud/client.py", line 215, in __init__
    _ClientProjectMixin.__init__(self, project=project)
  File ".../lib/python3.6/site-packages/google/cloud/client.py", line 169, in __init__
    project = self._determine_default(project)
  File ".../lib/python3.6/site-packages/google/cloud/datastore/client.py", line 222, in _determine_default
    return _determine_default_project(project)
  File ".../lib/python3.6/site-packages/google/cloud/datastore/client.py", line 75, in _determine_default_project
    project = _base_default_project(project=project)
  File ".../lib/python3.6/site-packages/google/cloud/_helpers.py", line 179, in _determine_default_project
    _, project = google.auth.default()
  File ".../lib/python3.6/site-packages/google/auth/_default.py", line 283, in default
    raise exceptions.DefaultCredentialsError(_HELP_MESSAGE)
google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or
explicitly create credential and re-run the application. For more

However, it's clear that these credentials are not actually required because when I initialize my client as follows, it works in both dev and production:

if os.environ.get(environment_vars.GCD_HOST):
    # avoid a bug in the google client - it tries to authenticate even when the emulator is enabled
    client = datastore.Client(_http=requests.Session)
else:
    client = datastore.Client()

With that change, the library works fine for me, but this seems like something the library ought to be able to detect and handle by default to save devs a lot of time.

In case they're relevant:

  1. OS type and version
$ uname -a
Darwin Rileys-MacBook-Pro.local 17.7.0 Darwin Kernel Version 17.7.0: Thu Jun 21 22:53:14 PDT 2018; root:xnu-4570.71.2~1/RELEASE_X86_64 x86_64
  1. Python version and virtual environment information python --version
$ python --version
Python 3.6.5
  1. google-cloud-python version pip show google-cloud, pip show google-<service> or pip freeze
$ pip show google-cloud-datastore
Name: google-cloud-datastore
Version: 1.7.0

Metadata

Metadata

Labels

api: datastoreIssues related to the googleapis/python-datastore API.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions