【问题标题】:Getting AccessTokenRefreshError 'invalid_grant' on dev_appserver when using cloudstorage使用云存储时在 dev_appserver 上获取 AccessTokenRefreshError 'invalid_grant'
【发布时间】:2016-12-05 13:55:54
【问题描述】:

在尝试Google Cloud Storage sample(或使用cloudstorage 模块写入文件的任何调用,在其他项目中也是如此)时,我收到以下错误

INFO     2016-12-05 01:16:06,999 client.py:804] Refreshing access_token
INFO     2016-12-05 01:16:07,198 client.py:827] Failed to retrieve access token: {
  "error" : "invalid_grant"
}
ERROR    2016-12-05 01:16:07,200 api_server.py:272] Exception while handling service_name: "app_identity_service"
method: "GetAccessToken"
request: "\n7https://www.googleapis.com/auth/devstorage.full_control"
request_id: "YpfXhQJczA"

... long long stack traces ...

RuntimeError: AccessTokenRefreshError(u'invalid_grant',)

问题是,当我将应用程序部署到 Google App Engine 时,调用工作正常。

【问题讨论】:

标签: python google-app-engine google-oauth google-cloud-storage


【解决方案1】:

我花了几个小时搜索和调试客户端代码,直到我发现oauth2client 正在使用一些存储在文件系统中的default application credentials。似乎这些凭据可能是以前版本的 GAE SDK 遗留下来的,其中包含一个被 Google 拒绝的旧刷新令牌。

在 Windows 上,这些凭据存储在

C:\Users\$USER\AppData\Roaming\gcloud\application_default_credentials.json

使用gcloud 工具可以轻松重新创建这些凭据:

$ gcloud auth application-default login

(请注意,gcloud auth login 仅设置使用 gcloud 实用程序本身的凭据,而不是为调用 Google 客户端库的应用设置凭据,因此这里不需要)。

希望这可以为其他人节省几个小时。

【讨论】:

  • 我可以确认这为我节省了几个小时。
猜你喜欢
  • 1970-01-01
  • 2015-03-04
  • 1970-01-01
  • 1970-01-01
  • 2013-04-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多