我只需要一种有效的方法来调试 GAE 应用程序,为此我需要在运行 dev_appserver.py 时从 localhost 连接到生产 GAE 基础架构。
如果我将其作为单独的脚本运行,则下一个代码运行良好:
import argparse
try:
import dev_appserver
dev_appserver.fix_sys_path()
except ImportError:
print('Please make sure the App Engine SDK is in your PYTHONPATH.')
raise
from google.appengine.ext import ndb
from google.appengine.ext.remote_api import remote_api_stub
def main(project_id):
server_name = '{}.appspot.com'.format(project_id)
remote_api_stub.ConfigureRemoteApiForOAuth(
app_id='s~' + project_id,
path='/_ah/remote_api',
servername=server_name)
# List the first 10 keys in the datastore.
keys = ndb.Query().fetch(10, keys_only=True)
for key in keys:
print(key)
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('project_id', help='Your Project ID.')
args = parser.parse_args()
main(args.project_id)
使用此脚本,我能够从远程 Datastore 获取数据。但是我需要在我的应用程序(显然不是单个脚本)中放置相同的代码以使其工作?我试图将remote_api_stub.ConfigureRemoteApiForOAuth()
代码放入其中,appengine_config.py
但出现递归错误。我正在运行这样的应用程序:
dev_appserver.py app.yaml --admin_port=8001 --enable_console --support_datastore_emulator=no --log_level=info
该应用程序使用 NDB 访问 Google Datastore。应用程序包含许多模块和文件,我根本不知道将 remote_api_stab 身份验证代码放在哪里。
我希望谷歌团队的人会看到这个话题,因为我已经搜索了所有的互联网,没有任何结果。难以置信有多少人为 GAE 平台开发应用程序,但看起来没有人在本地开发/调试应用程序。