AppEngine - 远程API返回401和太多身份验证

Bri*_*unt 4 python google-app-engine google-oauth2

我正在尝试使用远程API连接到AppEngine实例,如下所示:

os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = ".../path/to/key"
remote_api_stub.ConfigureRemoteApiForOAuth(
    server.encode('ascii'), path, secure=True
)
Run Code Online (Sandbox Code Playgroud)

path/to/key点在谷歌云(测试版)创建了一个JSON文件,API管理器- >凭证- >添加凭据- >服务帐户." 权限"面板中的"可以编辑"服务帐户.

当我运行它时,我在控制台上收到类似这样的错误,对应于401(在App Engine日志查看器中报告):

  File "/usr/local/share/app-engine-python/google/appengine/ext/remote_api/remote_api_stub.py", line 768, in ConfigureRemoteApiForOAuth
    rpc_server_factory=rpc_server_factory)
  File "/usr/local/share/app-engine-python/google/appengine/ext/remote_api/remote_api_stub.py", line 835, in ConfigureRemoteApi
    app_id = GetRemoteAppIdFromServer(server, path, rtok)
  File "/usr/local/share/app-engine-python/google/appengine/ext/remote_api/remote_api_stub.py", line 569, in GetRemoteAppIdFromServer
    response = server.Send(path, payload=None, **urlargs)
  File "/usr/local/share/app-engine-python/google/appengine/tools/appengine_rpc_httplib2.py", line 258, in Send
    NeedAuth()
  File "/usr/local/share/app-engine-python/google/appengine/tools/appengine_rpc_httplib2.py", line 234, in NeedAuth
    RaiseHttpError(url, response_info, response, 'Too many auth attempts.')
  File "/usr/local/share/app-engine-python/google/appengine/tools/appengine_rpc_httplib2.py", line 85, in RaiseHttpError
    raise urllib2.HTTPError(url, response_info.status, msg, response_info, stream)
urllib2.HTTPError: HTTP Error 401: Unauthorized Too many auth attempts.

我检查了,似乎设置了正确的凭据/google/appengine/ext/remote_api/remote_api_stub.py:760,应该传递给远程api.

app.yaml具有基本设置- remote_api: onbuiltins.

此设置适用于本地dev_appserver.py,因此我认为问题出在Google服务器/云设置上.

我在App Engine - >设置 - >应用程序设置(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
Run Code Online (Sandbox Code Playgroud)

也给出了相同的401异常.

小智 8

刚刚遇到这个问题,这里没有解决它。唯一对我有用的是将--secure选项添加到远程 shell 命令

$APPENGINE/remote_api_shell.py  --secure -s my-app.appspot.com
Run Code Online (Sandbox Code Playgroud)


Bri*_*unt 6

好的,所以似乎有必要:

  1. 转到appspot.com管理页面.
  2. 在应用程序设置下,启用云集成
  3. 新的云控制台页面API Manager中创建新的服务帐户(现有服务帐户似乎不起作用)
  4. 切换到remote_api_stub.ConfigureRemoteApiFromServer - 进一步检查,似乎ConfigureRemoteApiForOAuth工作正常.

至少在执行上述访问后按预期工作.

我希望其他人也能找到这样的帮助.

编辑这可能与此主题中讨论的问题有关:https://groups.google.com/forum/?utm_medium = email&utm_source = footer#! msg/google-cloud -inside / ohnp1XAOdiM/KrQF8_DAAAAJ