【发布时间】:2014-03-15 09:43:21
【问题描述】:
我正在尝试按照 Google 文档 (https://developers.google.com/appengine/docs/python/tools/remoteapi) 中的说明在本地客户端中使用远程 API。
我第一次尝试从远程 API 外壳,一切正常。我可以连接到我的远程数据存储并获取数据。
但是当我运行以下脚本时,这与谷歌的示例非常相似:
#!/opt/local/bin/python2.7
import sys
SDK_PATH = "/usr/local/google_appengine/"
sys.path.append(SDK_PATH)
import dev_appserver
dev_appserver.fix_sys_path()
from google.appengine.ext.remote_api import remote_api_stub
import model.account
def auth_func():
return ('myaccount', 'mypasswd')
remote_api_stub.ConfigureRemoteApi('myappid', '/_ah/remote_api', auth_func)
# Fetch some data
entries = model.account.list()
for a in entries:
print a.name
然后我得到一个错误:
Traceback (most recent call last):
File "./remote_script_test.py", line 26, in <module>
entries = model.account.list()
[...]
File "/Developer/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/datastore/datastore_rpc.py", line 1333, in check_rpc_success
raise _ToDatastoreError(err)
google.appengine.api.datastore_errors.BadRequestError: Application Id (app) format is invalid: '_'
它说我的应用程序 ID 是一个简单的下划线“_”,但事实并非如此,因为我的 app.yaml 已正确配置并且当我执行时
print app_identity.get_application_id()
从该脚本中,我得到了正确的应用程序 ID。我的印象是 GAE 环境设置不正确,但我不知道如何使它工作。有没有人有在这种情况下工作的完整代码?
我正在使用 Mac Os X Mountain Lion。
【问题讨论】:
-
你的model.account中有什么?
-
model.account 使用 NDB API 定义了一个简单的模型类。 list() 方法进行查询以获取数据库中的所有条目。没什么特别的,该模型在网络应用程序中运行良好。