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.