我正在编写简单的代码来访问dev服务器。模拟的dev服务器和数据存储区都已在本地启动。
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
答案 0 :(得分:2)
GAE应用代码无法作为独立 python应用运行,它只能在您的开发服务器内运行的GAE应用内运行。通常作为处理程序代码的一部分,通过对dev服务器的http请求触发。
您需要将该代码放在一个应用处理程序中。例如,在main.py
Quickstart for Python App Engine Standard Environment中的get()
处理程序的MainPage
方法内部(实际上它在post()
方法中更好,因为您的代码是写入数据存储区。)