【发布时间】:2015-10-27 21:15:45
【问题描述】:
我正在尝试使用远程 API 连接到 AppEngine 实例,如下所示:
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = ".../path/to/key"
remote_api_stub.ConfigureRemoteApiForOAuth(
server.encode('ascii'), path, secure=True
)
path/to/key 指向在 Google Cloud(测试版)中创建的 JSON 文件,API Manager -> Credentials -> Add Credentials -> Service Account。 权限面板中的服务帐户“可以编辑”。
当我运行它时,我在控制台上收到类似这样的错误,对应于 401(在 App Engine 日志查看器中报告):
文件“/usr/local/share/app-engine-python/google/appengine/ext/remote_api/remote_api_stub.py”,第 768 行,在 ConfigureRemoteApiForOAuth rpc_server_factory=rpc_server_factory) 文件“/usr/local/share/app-engine-python/google/appengine/ext/remote_api/remote_api_stub.py”,第 835 行,在 ConfigureRemoteApi app_id = GetRemoteAppIdFromServer(服务器,路径,rtok) GetRemoteAppIdFromServer 中的文件“/usr/local/share/app-engine-python/google/appengine/ext/remote_api/remote_api_stub.py”,第 569 行 响应 = server.Send(路径,有效负载 = 无,**urlargs) 发送中的文件“/usr/local/share/app-engine-python/google/appengine/tools/appengine_rpc_httplib2.py”,第 258 行 需要验证() NeedAuth 中的文件“/usr/local/share/app-engine-python/google/appengine/tools/appengine_rpc_httplib2.py”,第 234 行 RaiseHttpError(url, response_info, response, '太多的身份验证尝试。') RaiseHttpError 中的文件“/usr/local/share/app-engine-python/google/appengine/tools/appengine_rpc_httplib2.py”,第 85 行 raise urllib2.HTTPError(url, response_info.status, msg, response_info, stream) urllib2.HTTPError:HTTP 错误 401:未经授权的身份验证尝试次数过多。我检查了一下,似乎在/google/appengine/ext/remote_api/remote_api_stub.py:760 中设置了正确的凭据,应该传递给远程 api。
app.yaml 在builtins 下具有基本设置- remote_api: on。
此设置适用于本地 dev_appserver.py,因此我相信问题出在 Google 服务器/云设置上。
我在 App Engine -> Settings -> Application settings(Google Accounts API 和 Google Apps 域)中尝试了两种身份验证方案。
我尽可能地关注Google Application Default Credentials,但也许我错过了什么?
可能还值得注意的是,从命令行:
$ GOOGLE_APPLICATION_CREDENTIALS=~/path-to-key
remote_api_shell.py -s APPID.appspot.com --secure APPID
也给出了相同的 401 异常。
【问题讨论】:
标签: python google-app-engine google-oauth