0

I am new to google cloud datastore. I tried this documentation on getting started with google cloud datastore in python. I made the trivial example work on my terminal.

So, I tried to run the same code as a service on google app engine under the same project my compute engine for my cloud datastore is running.

This is my code:

import googledatastore as datastore

def data_store_test(self):
   datastore.set_options(dataset='my-dataset-id')
   # Create a RPC request to begin a new transaction.
   req = datastore.BeginTransactionRequest()
   # Execute the RPC synchronously.
   resp = datastore.begin_transaction(req)

And when I ran this code in my app engine I got this error on the last line of the code:

Traceback (most recent call last):
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1535, in __call__
rv = self.handle_exception(request, response, e)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1529, in __call__
rv = self.router.dispatch(request, response)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1278, in default_dispatcher
return route.handler_adapter(request, response)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1102, in __call__
return handler.dispatch()
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 572, in dispatch
return self.handle_exception(e, self.app.debug)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 570, in dispatch
return method(*args, **kwargs)
  File "/base/data/home/apps/s~my-dataset-id/0-0-1.377819373230447398/handlers/test_handler.py", line 49, in data_store_test
datastore.begin_transaction(req)
  File "/base/data/home/apps/s~my-dataset-id/0-0-1.377819373230447398/googledatastore/__init__.py", line 85, in begin_transaction
return get_default_connection().begin_transaction(request)
  File "/base/data/home/apps/s~my-dataset-id/0-0-1.377819373230447398/googledatastore/__init__.py", line 66, in get_default_connection
_options['credentials'] = helper.get_credentials_from_env()
  File "/base/data/home/apps/s~my-dataset-id/0-0-1.377819373230447398/googledatastore/helper.py", line 70, in get_credentials_from_env
credentials.refresh(http)
  File "/base/data/home/apps/s~my-dataset-id/0-0-1.377819373230447398/oauth2client/client.py", line 516, in refresh
self._refresh(http.request)
  File "/base/data/home/apps/s~my-dataset-id/0-0-1.377819373230447398/oauth2client/gce.py", line 82, in _refresh
response, content = http_request(uri)
  File "/base/data/home/apps/s~my-dataset-id/0-0-1.377819373230447398/oauth2client/util.py", line 132, in positional_wrapper
return wrapped(*args, **kwargs)
  File "/base/data/home/apps/s~my-dataset-id/0-0-1.377819373230447398/oauth2client/client.py", line 475, in new_request
self._refresh(request_orig)
  File "/base/data/home/apps/s~my-dataset-id/0-0-1.377819373230447398/oauth2client/gce.py", line 82, in _refresh
response, content = http_request(uri)
  File "/base/data/home/apps/s~my-dataset-id/0-0-1.377819373230447398/httplib2/__init__.py", line 1570, in request
(response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File "/base/data/home/apps/s~my-dataset-id/0-0-1.377819373230447398/httplib2/__init__.py", line 1317, in _request
(response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "/base/data/home/apps/s~my-dataset-id/0-0-1.377819373230447398/httplib2/__init__.py", line 1286, in _conn_request
response = conn.getresponse()
  File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/gae_override/httplib.py", line 534, in getresponse
'An error occured while connecting to the server: %s' % e)
error: An error occured while connecting to the server: DNS lookup failed for URL: http://metadata.google.internal/0.1/meta-data/service-accounts/default/acquire?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdatastore%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email

I had to set the credentials(DATASTORE_PRIVATE_KEY_FILE, DATASTORE_SERVICE_ACCOUNT) in environment variable to make this code to work on terminal. As I am running this code under the same project where I have my could datastore I Thought I don't have to give those credentials.

Do I have to run this app engine code under vm instance by adding the line "vm: true" in app.yaml file?

I feel like I am missing a small think here but I don't know what it is. Please help me with this.

Anand S
  • 1,068
  • 9
  • 22

1 Answers1

0

For direct access to the Datastore from an App Engine application, we recommend using the Python DB Datastore API or the Python NDB Datastore API.

The Cloud Datastore Python API is designed for accessing Cloud Datastore from other environments such as Google Compute Engine.

Ed Davisson
  • 2,927
  • 11
  • 11
  • I thought, I can't access the cloud datastore like an regular datastore. Thanks for making me understand that is wrong. How do i access this datastore form different App Engine application? – Anand S Aug 12 '14 at 12:11
  • Should I use google cloud endpoints for accessing cloud datastore? Which will be an efficient way? – Anand S Aug 12 '14 at 15:48
  • Will i be able to query the cloud datastore directly from other App Engine applications? – Anand S Aug 12 '14 at 17:07
  • Cloud Datastore is an API for accessing the App Engine Datastore from outside of App Engine. If you're using Google Cloud Endpoints, your code is running on App Engine, so you should use the DB or NDB API I mentioned above. We don't currently document a way to access one app's Datastore from another app, but you might find this question helpful: http://stackoverflow.com/questions/8956230/can-i-access-datastore-entities-of-my-other-google-app-engine-applications. – Ed Davisson Aug 12 '14 at 20:43