GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Datastore / Pubsub emulators break when using default credentials · Issue #1839 · googleapis/google-cloud-python

Datastore / Pubsub emulators break when using default credentials #1839

New issue
Copy link
New issue
Copy link
Closed
Closed
Datastore / Pubsub emulators break when using default credentials#1839
Copy link
Assignees
dhermes
Labels
api: datastoreIssues related to the Datastore API.

Description

@txomon
txomon
opened on May 31, 2016
Issue body actions

For clarity / brevity (edit by @dhermes). When using just the default credentials, the oauth2client refresh tries to generate an access token and append one to a datastore / pubsub request. However, this is not needed and can cause breakage.

There is a workaround in both datastore and pubsub. We should determine if this should be "fixed" with docs or with custom credential usage in the Connection constructors.


Original report by @txomon :
#1837 2nd issue

I think it is about mistakenly patching httplib for local testing.

Test script

from gcloud import datastore

client = datastore.Client()
entity = datastore.Entity(client.key('Test1'))
client.put(entity)

Setting up environment

This one needs:

  • Application default credentials set up

Showcase

I think this manifests with a Connection refused error:

(ve) javier@theoden:~/projects/spinoffs/gae$ python test-script.py 
Traceback (most recent call last):
  File "test-script.py", line 5, in <module>
    client.put(entity)
  File "/home/javier/projects/spinoffs/gae/ve/lib/python3.4/site-packages/gcloud/datastore/client.py", line 319, in put
    self.put_multi(entities=[entity])
  File "/home/javier/projects/spinoffs/gae/ve/lib/python3.4/site-packages/gcloud/datastore/client.py", line 345, in put_multi
    current.commit()
  File "/home/javier/projects/spinoffs/gae/ve/lib/python3.4/site-packages/gcloud/datastore/batch.py", line 260, in commit
    self._commit()
  File "/home/javier/projects/spinoffs/gae/ve/lib/python3.4/site-packages/gcloud/datastore/batch.py", line 243, in _commit
    self.project, self._commit_request, self._id)
  File "/home/javier/projects/spinoffs/gae/ve/lib/python3.4/site-packages/gcloud/datastore/connection.py", line 331, in commit
    _datastore_pb2.CommitResponse)
  File "/home/javier/projects/spinoffs/gae/ve/lib/python3.4/site-packages/gcloud/datastore/connection.py", line 121, in _rpc
    data=request_pb.SerializeToString())
  File "/home/javier/projects/spinoffs/gae/ve/lib/python3.4/site-packages/gcloud/datastore/connection.py", line 93, in _request
    method='POST', headers=headers, body=data)
  File "/home/javier/projects/spinoffs/gae/ve/lib/python3.4/site-packages/oauth2client/client.py", line 631, in new_request
    redirections, connection_type)
  File "/home/javier/projects/spinoffs/gae/ve/lib/python3.4/site-packages/httplib2/__init__.py", line 1314, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File "/home/javier/projects/spinoffs/gae/ve/lib/python3.4/site-packages/httplib2/__init__.py", line 1064, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "/home/javier/projects/spinoffs/gae/ve/lib/python3.4/site-packages/httplib2/__init__.py", line 987, in _conn_request
    conn.connect()
  File "/usr/lib/python3.4/http/client.py", line 871, in connect
    self.timeout, self.source_address)
  File "/usr/lib/python3.4/socket.py", line 516, in create_connection
    raise err
  File "/usr/lib/python3.4/socket.py", line 507, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

This is caused because it tries to make a auth token refresh against the emulator. There are no relevant logs for the emulator.

Workaround

I thought I had found a workaround but I cannot reproduce the workaround, therefore not a workaround.

The problem is the default credential, so it can be fixed by (ordered by personal preference):

  1. Create a configuration with no default credentials, for the same project, or;
  2. ~~Remove the default credentials gcloud beta auth application-default revoke~~~

Hopefully you know how to patch the library not to collide!

Activity

  1. tseaver
    added
    api: datastoreIssues related to the Datastore API.
    on May 31, 2016
  2. txomon commented on May 31, 2016

    @txomon
    txomon
    on May 31, 2016
    Author
    More actions

    When no default credentials exist, the following error is triggered:

    (ve34) javier@theoden:~/projects/spinoffs/gae$ python test-script.py 
    Traceback (most recent call last):
      File "test-script.py", line 3, in <module>
        client = datastore.Client()
      File "/home/javier/ve34/lib/python3.4/site-packages/gcloud-0.12.0-py3.4.egg/gcloud/datastore/client.py", line 173, in __init__
        super(Client, self).__init__(credentials, http)
      File "/home/javier/ve34/lib/python3.4/site-packages/gcloud-0.12.0-py3.4.egg/gcloud/client.py", line 122, in __init__
        credentials = get_credentials()
      File "/home/javier/ve34/lib/python3.4/site-packages/gcloud-0.12.0-py3.4.egg/gcloud/credentials.py", line 82, in get_credentials
        return client.GoogleCredentials.get_application_default()
      File "/home/javier/ve34/lib/python3.4/site-packages/oauth2client-2.1.0-py3.4.egg/oauth2client/client.py", line 1398, in get_application_default
      File "/home/javier/ve34/lib/python3.4/site-packages/oauth2client-2.1.0-py3.4.egg/oauth2client/client.py", line 1388, in _get_implicit_credentials
    oauth2client.client.ApplicationDefaultCredentialsError: The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.
    
  3. txomon commented on May 31, 2016

    @txomon
    txomon
    on May 31, 2016
    Author
    More actions

    Ok, I have found something really strange.

    Datastore running:

    javier@theoden ~/p/s/gae> bash
    sessions should be nested with care, unset $TMUX to force
    sessions should be nested with care, unset $TMUX to force
    javier@theoden:~/projects/spinoffs/gae$ activate 34
    (ve34) javier@theoden:~/projects/spinoffs/gae$ $(gcloud beta emulators datastore env-init)                                                                                                                         
    (ve34) javier@theoden:~/projects/spinoffs/gae$ python test-script.py 
    Traceback (most recent call last):
      File "test-script.py", line 5, in <module>
        client.put(entity)
      File "/home/javier/ve34/lib/python3.4/site-packages/gcloud-0.12.0-py3.4.egg/gcloud/datastore/client.py", line 319, in put
        self.put_multi(entities=[entity])
      File "/home/javier/ve34/lib/python3.4/site-packages/gcloud-0.12.0-py3.4.egg/gcloud/datastore/client.py", line 345, in put_multi
        current.commit()
      File "/home/javier/ve34/lib/python3.4/site-packages/gcloud-0.12.0-py3.4.egg/gcloud/datastore/batch.py", line 260, in commit
        self._commit()
      File "/home/javier/ve34/lib/python3.4/site-packages/gcloud-0.12.0-py3.4.egg/gcloud/datastore/batch.py", line 243, in _commit
        self.project, self._commit_request, self._id)
      File "/home/javier/ve34/lib/python3.4/site-packages/gcloud-0.12.0-py3.4.egg/gcloud/datastore/connection.py", line 327, in commit
        _datastore_pb2.CommitResponse)
      File "/home/javier/ve34/lib/python3.4/site-packages/gcloud-0.12.0-py3.4.egg/gcloud/datastore/connection.py", line 117, in _rpc
        data=request_pb.SerializeToString())
      File "/home/javier/ve34/lib/python3.4/site-packages/gcloud-0.12.0-py3.4.egg/gcloud/datastore/connection.py", line 93, in _request
        error_status = status_pb2.Status.FromString(content)
      File "/home/javier/ve34/lib/python3.4/site-packages/protobuf-3.0.0b3-py3.4.egg/google/protobuf/internal/python_message.py", line 780, in FromString
        message.MergeFromString(s)
      File "/home/javier/ve34/lib/python3.4/site-packages/protobuf-3.0.0b3-py3.4.egg/google/protobuf/internal/python_message.py", line 1083, in MergeFromString
        raise message_mod.DecodeError('Unexpected end-group tag.')
    google.protobuf.message.DecodeError: Unexpected end-group tag.
    

    Datastore outputs:

    [datastore] May 31, 2016 10:52:52 PM com.google.appengine.tools.development.LocalResourceFileServlet doGet
    [datastore] WARNING: No file found for: /v1beta3/projects/testing:commit
    

    No idea on the reason...

  4. dhermes commented on May 31, 2016

    @dhermes
    dhermes
    on May 31, 2016
    Contributor
    More actions

    Thanks for filing. We have a workaround for do-nothing credentials in our system test.

    I'd imagine your Unexpected end-group tag error comes from an invalid request being sent.

  5. dhermes
    changed the title [-]Testing datastore default_credentials are used[/-] [+]Datastore / Pubsub emulators break when using default credentials[/+] on May 31, 2016
  6. txomon commented on May 31, 2016

    @txomon
    txomon
    on May 31, 2016
    Author
    More actions

    @dhermes The script is the one specified. My guess is that a file is missing there, https://github.com/googleapis/googleapis/blob/master/google/datastore/v1beta3/datastore.proto really looks like everything is in a file

  7. bendemaree commented on May 31, 2016

    @bendemaree
    bendemaree
    on May 31, 2016
    More actions

    @txomon Try gcloud==0.12.1. Until that release, the path to the emulator needed to be manually specified to include /datastore, as in the request to the datastore should be /datastore/v1beta3/projects/testing:commit (the URL given in the emulator's error really isn't being served).

    The workaround for 0.12.0 for us was to specify DATASTORE_HOST=http://localhost:8080/datastore rather than DATASTORE_HOST=http://localhost:8080.

  8. dhermes commented on May 31, 2016

    @dhermes
    dhermes
    on May 31, 2016
    Contributor
    More actions

    @bendemaree I assume you mean gcloud>=0.12.1?

  9. bendemaree commented on May 31, 2016

    @bendemaree
    bendemaree
    on May 31, 2016
    More actions

    Yes. I was assuming @txomon wanted that release for a specific release series vs. newer one and that's the highest for 0.12.x. 🙂

    Reacted by Danny Hermes and Javier Domingo Cansino
  10. txomon commented on May 31, 2016

    @txomon
    txomon
    on May 31, 2016
    Author
    More actions

    I think this can be specified as resolved maybe? I would create a Feature request ticket to have a way not to do that do-nothing credentials setup however.

    The trouble was coming indeed from overlapping several emulator instances (connection refused) / restarts, and old version of gcloud and not having setup do-nothing account credentials from the code.

  11. dhermes commented on Jun 7, 2016

    @dhermes
    dhermes
    on Jun 7, 2016
    Contributor
    More actions

    Gotcha. Thanks.

  12. dhermes
    closed this as completedon Jun 7, 2016
  13. nicolaslecrique
    added a commit that references this issue on Jun 18, 2016

    Migrate dal from ndb to gcloud datastore

    30fe0de
  14. nicolaslecrique
    added 2 commits that reference this issue on Jul 30, 2016

    Migrate dal from ndb to gcloud datastore

    6304daa

    Migrate dal from ndb to gcloud datastore

    b8eb879
  15. JustinBeckwith
    assigned
    dhermes
    on Feb 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @dhermes
    dhermes

Labels

api: datastoreIssues related to the Datastore API.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.