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 #1839DescriptionFor 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):
Create a configuration with no default credentials, for the same project, or;
- ~~Remove the default credentials
gcloud beta auth application-default revoke~~~
Hopefully you know how to patch the library not to collide! Activitytxomon commented on May 31, 2016 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.
txomon commented on May 31, 2016 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... dhermes commented on May 31, 2016 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. changed the title [-]Testing datastore default_credentials are used[/-] [+]Datastore / Pubsub emulators break when using default credentials[/+] on May 31, 2016txomon commented on May 31, 2016 bendemaree commented on May 31, 2016 @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. dhermes commented on May 31, 2016 bendemaree commented on 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. 🙂 Reacted by Danny Hermes and Javier Domingo Cansino txomon commented on May 31, 2016 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. dhermes commented on Jun 7, 2016
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|