Python 获取AccessTokenRefreshError';无效的授权';使用cloudstorage时在dev_appserver上
在尝试(或在其他项目中使用Python 获取AccessTokenRefreshError';无效的授权';使用cloudstorage时在dev_appserver上,python,google-app-engine,google-oauth,google-cloud-storage,Python,Google App Engine,Google Oauth,Google Cloud Storage,在尝试(或在其他项目中使用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-0
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',)
问题是,当我将应用程序部署到谷歌应用程序引擎时,调用工作正常 我花了几个小时搜索和调试客户机代码,直到发现
oauth2client
正在使用文件系统中某个存储的代码。似乎这些凭证(可能是以前版本的GAE SDK遗留下来的)包含了一个被谷歌拒绝的旧刷新令牌
在windows上,这些凭据存储在
C:\Users\$USER\AppData\Roaming\gcloud\application_default_credentials.json
使用gcloud
工具可以轻松地重新创建这些凭据:
$ gcloud auth application-default login
(请注意,gcloud auth login
仅为使用gcloud
实用程序本身设置凭据,而不用于调用Google客户端库的应用程序,因此此处不需要设置凭据)
希望这能为其他人节省几个小时 我可以确认这节省了我几个小时。请尝试导出GOOGLE\u APPLICATION\u CREDENTIALS=PATH/FILE.json。查看更多: