python - GAE NDB 数据存储新功能 : Access Datastore entities from other GAE app

标签 python google-app-engine google-cloud-datastore

阅读 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/

相关文章:

python - Beautiful Soup 找不到这个 html

google-app-engine - 从 Appengine (JAVA) 更改 Google Cloud Storage 的 ACL

python - 有效地找到实体计数 Google App Engine

python - 如何覆盖 python 应用引擎模型上的 put() 方法?

python - 使用一些可选参数运行 python 脚本

python - 编排小型 Python 任务的最佳实践(大多数在 BigQuery 中执行 SQL)

python - GAE ndb 按键(id)过滤

java - 帮助我决定使用 Google App Engine 来完成这项实际工作

java - 在 for 循环中创建多个 Google App Engine 实体

google-cloud-datastore - Google数据存储模拟器Web控制台