question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Datastore / Pubsub emulators break when using default credentials

See original GitHub issue

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!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
bendemareecommented, May 31, 2016

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. 🙂

0reactions
dhermescommented, Jun 7, 2016

Gotcha. Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Google Cloud Datastore Emulator does not use default ...
In theory you should be able to use mock credentials, e.g.: class EmulatorCreds(google.auth.credentials.Credentials): def __init__(self): ...
Read more >
Using the Default App Engine Service Account - Google Cloud
Your App Engine app uses the credentials of the App Engine service account by default. For more information, see Granting your app access...
Read more >
Spring Cloud GCP
Spring Cloud GCP Pub/Sub API Configuration. This section describes options for enabling the integration, specifying the GCP project and credentials, and setting ...
Read more >
Google Cloud Client Libraries for Go - Go Packages
By default, all requests in sub-packages will run indefinitely, ... be ineffective and would only interfere with credential refreshing, ...
Read more >
Google Provider Configuration Reference - Terraform Registry
The google and google-beta provider blocks are used to configure the credentials you use to authenticate with GCP, as well as a default...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found