GAE: AssertionError: No api proxy found for service "datastore_v3"

GAE: AssertionError: No api proxy found for service "datastore_v3"

我正在编写简单的代码来访问开发服务器。开发服务器和模拟的数据存储都已在本地启动。

from google.appengine.ext import ndb

class Account(ndb.Model):
    name = ndb.StringProperty()

acc = Account(name=u"test").put()
print(acc)

错误:

AssertionError: No api proxy found for service "datastore_v3"

我尝试设置:export DATASTORE_EMULATOR_HOST=localhost:8760。没用。

$ dev_appserver.py  ./app.yaml 
WARNING  2017-02-20 06:40:23,130 application_configuration.py:176] The "python" runtime specified in "./app.yaml" is not supported - the "python27" runtime will be used instead. A description of the differences between the two can be found here:
https://developers.google.com/appengine/docs/python/python25/diff27
INFO     2017-02-20 06:40:23,131 devappserver2.py:764] Skipping SDK update check.
INFO     2017-02-20 06:40:23,508 api_server.py:268] Starting API server at: http://localhost:53755
INFO     2017-02-20 06:40:23,514 dispatcher.py:199] Starting module "default" running at: http://localhost:8080
INFO     2017-02-20 06:40:23,517 admin_server.py:116] Starting admin server at: http://localhost:8000

GAE 应用程序代码不能 运行 作为 独立 python 应用程序,它只能 运行 在 GAE 中app which 运行s inside your dev server.通常作为处理程序代码的一部分,通过对开发服务器的 http 请求触发。

您需要将该代码放入您的一个应用程序处理程序中。例如,在 main.py in the Quickstart for Python App Engine Standard EnvironmentMainPage 处理程序的 get() 方法中(实际上,在 post() 方法中会更好,因为您的代码正在写入数据存储区)。