【问题标题】:AppEngine - Remote API returning 401 and too-many-authAppEngine - 返回 401 和太多身份验证的远程 API
【发布时间】: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.yamlbuiltins 下具有基本设置- 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


    【解决方案1】:

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

    $APPENGINE/remote_api_shell.py  --secure -s my-app.appspot.com
    

    【讨论】:

      【解决方案2】:

      好吧,看来有必要的是:

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

      至少在按预期执行上述访问之后。

      我希望其他类似情况的人觉得这很有帮助。

      【讨论】:

      【解决方案3】:

      对于从命令行(bulkloader.pyremote_api_shell.py 等)使用远程 api 的人,如果您的 appengine cookie 已过期,也可能会发生 401 错误。

      尝试删除它们并再次验证:

      rm ~/.appcfg* gcloud auth login

      这可能发生在对 Google 帐户进行更改强制退出(例如:启用 2 因素身份验证)的情况下。

      【讨论】:

      • 在我的情况下,与多个专业和私人 GAE 项目合作,只需重新运行 gcloud auth login 即可解决错误。
      • @BuffaloRabor 您也可以使用gcloud config set accountgcloud auth list 查看帐户),它不会提示进入 oauth2 屏幕,而只是重复使用您之前生成的令牌。 gcloud auth login 更强大一点,rm ~/.appcfg_cookies 是最极端的解决方案。我通常也使用gcloud auth login,但是我启用2因素身份验证的时间还不够。
      猜你喜欢
      • 1970-01-01
      • 2019-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-05
      • 2016-10-02
      • 2013-06-12
      • 1970-01-01
      相关资源
      最近更新 更多