【发布时间】:2016-12-27 23:45:11
【问题描述】:
我正在尝试在未在 Google App Engine 上运行的 Python Django 项目中实现 Google Cloud DataStore。
是否可以在不让项目在 Google App Engine 上运行的情况下使用 Google Datastore?如果是,请问如何检索完整的实体对象或成功执行查询?
下面的代码 sn-p 打印查询对象,但之后抛出错误。
代码片段:
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)
错误:
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.
【问题讨论】:
-
可以在 App Engine 之外使用 Datastore,但您需要有一个有效的 Google Cloud Platform 项目。你有其中之一吗?
-
@MeLight 是的。我有一个有效的项目。它也在错误中打印项目。
-
在代码中添加 'print(vars(client))' 也会显示正确的项目值。而且我还没有在这段代码 sn-p 的任何地方指定项目值。
-
您还需要根据错误创建一个App Engine项目。之后,您应该能够使用正确的库和身份验证的数据存储
-
好的。会再试一次。谢谢
标签: python google-app-engine google-cloud-storage google-cloud-platform google-cloud-datastore