2

I am trying to Implement Google Cloud DataStore in my Python Django Project not running on Google App Engine.

Can it be possible to use Google Datastore without having the project run on Google App Engine ? If yes, Can you please tell how to retrieve the complete entity object or execute the query successfully ?

The below code snippet prints the query object but throws an error after that.

Code Snippet:

from gcloud import datastore
entity_kind = 'EntityKind'
numeric_id = 1234

client = datastore.Client()
key = client.key(entity_kind, numeric_id)
query = client.query(kind=entity_kind)
print(query)
results = list(query.fetch())
print(results)

Error:

NotFound: 404 The project gproj does not exist or it does not contain an active App Engine application. Please visit http://console.developers.google.com to create a project or https://console.developers.google.com/appengine?project=gproj to add an App Engine application. Note that the app must not be disabled.
6
  • It is possible to use Datastore outside of App Engine, but you need to have a valid Google Cloud Platform project. Do you have one of those? Commented Aug 21, 2016 at 8:54
  • @MeLight yes. I have a valid project. It prints the project too in the Error. Commented Aug 21, 2016 at 9:25
  • Adding 'print(vars(client))' in the code shows the correct project value too. And I haven't specified the project value anywhere in this code snippet. Commented Aug 21, 2016 at 9:28
  • You also need to create an App Engine project as per the error. After that you should be able to use the datastore given the right libraries and authentication Commented Aug 21, 2016 at 10:21
  • ok. will give it a try again. Thanks Commented Aug 21, 2016 at 14:51

1 Answer 1

2

This guide will probably be helpful. You can see an example of it in action here.

You just need to pass a project id to the .Client() method:

datastore.Client("YOUR_PROJECT_ID")

You can also skip this part by running this command before running your app:

$ gcloud beta auth application-default login

If you run that, it will authenticate all of your requests locally without injecting the project id :)

Hope this helps!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.