阅读 GAE NDB 数据存储的新文档: https://cloud.google.com/appengine/docs/python/ndb/modelclass#class_methods
get_by_id(id, parent=None, app=None, namespace=None, **ctx_options)
Returns an entity by ID. This is really just a shorthand for
Key(cls, id).get()
.Arguments
id
A string or integer key ID. parent Parent key of the model to get.
app
(keyword arg) ID of app. If not specified, gets data for current app.
namespace
(keyword arg) Namespace. If not specified, gets data for default namespace.
**ctx_options
Context options Returns a model instance or None if not found.
我发现了这个新的 app
参数。这是我很久以前就需要的!!!!!
我刚刚尝试从应用程序“xxxxxglobal”访问应用程序“xxxxxdev”的数据存储,但出现此错误:
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/datastore/datastore_rpc.py", line 1373, in check_rpc_success
raise _ToDatastoreError(err)
BadRequestError: app s~xxxxxglobal cannot access app xxxxxxdev's data
我在此链接中将帐户服务 xxxxxdev@appspot.gserviceaccount.com 和 xxxxxglobal@appspot.gserviceaccount.com 添加为彼此的管理员: https://console.cloud.google.com/iam-admin/iam/
但我仍然收到问题。
谁能帮帮我?我需要知道我可以在控制面板的哪个位置向 App Engine 中的其他应用程序授予数据存储区访问权限。
最佳答案
目前,ndb 不使用 Cloud Datastore API,并且在其正常操作模式下无法连接到另一个应用程序的数据存储区 - 它 native 连接到运行代码的应用程序的数据存储区。
但是,您可以使用 remote api让 ndb 从开发环境连接到不同应用程序的数据存储。
当前 [Public Issue Tracker for App Engine 中有一个开放的功能请求|从单个应用程序访问多个数据存储的可能性。尽管来自 the following comments in the source,但请随意发布针对 ndb 的功能请求看来这已经在进行中了:
current_app_id = os.environ.get('APPLICATION_ID', None)
if current_app_id and current_app_id != app_id:
# TODO(pcostello): We should support this so users can connect to different
# applications.
raise ValueError('Cannot create a Cloud Datastore context that connects '
'to an application (%s) that differs from the application '
'already connected to (%s).' % (app_id, current_app_id))
os.environ['APPLICATION_ID'] = app_id
关于python - GAE NDB 数据存储新功能 : Access Datastore entities from other GAE app,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37582110/