GAE: AssertionError: No api proxy found for servic

2019-02-28 16:23发布

问题:

I'm writing simple to code to access dev server. Both dev server and datastore emulated have been started locally.

from google.appengine.ext import ndb

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

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

Error:

AssertionError: No api proxy found for service "datastore_v3"

I tried to set: export DATASTORE_EMULATOR_HOST=localhost:8760 . It does not help.

$ 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

回答1:

GAE app code cannot run as a standalone python app, it can only run inside a GAE app which runs inside your dev server. Typically as part of a handler code, triggered via http requests to the dev server.

You need to put that code inside one of your app handlers. For example inside the get() method of the MainPage handler from main.py in the Quickstart for Python App Engine Standard Environment (actually it'd be better in a post() method since your code is writing to the datastore).