【问题标题】:Application ID error with GAE remote APIGAE 远程 API 的应用程序 ID 错误
【发布时间】: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() 方法进行查询以获取数据库中的所有条目。没什么特别的,该模型在网络应用程序中运行良好。

标签: python google-app-engine


【解决方案1】:

您可能希望从 remote_api_shell.py 开始并删除东西直到它损坏,而不是添加东西直到它工作。

例如,在您复制的那一行之后有一行:remote_api_stub.MaybeInvokeAuthentication() 有必要吗? remote_api_shell.py 中可能有许多必要的行,也许更好地自定义而不是从头开始。

【讨论】:

  • 嗯,这是个好建议!实际上,使用 remote_api_shell.py 似乎我所要做的就是在 remote_api_stub 初始化之后移动我的模型模块的导入语句:remote_api_stub.ConfigureRemoteApi('myappid', '/_ah/remote_api', auth_func),然后是import model.account。我不太明白为什么,但它有效!
  • 很高兴听到这个消息!我想这有点道理。例如,在导入 ndb 之前,remote_api 可能需要覆盖一些数据存储 rpc 函数。
猜你喜欢
  • 1970-01-01
  • 2017-02-18
  • 1970-01-01
  • 1970-01-01
  • 2017-08-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-05
相关资源
最近更新 更多