我使用gcloud app deploy部署应用程序 . 它运行良好几个小时,然后工作陷入以下信息日志:
03:54:59.748 Refreshing due to a 401 (attempt 1/2)
03:58:44.816 Refreshing due to a 401 (attempt 1/2)
03:58:55.781 Refreshing due to a 401 (attempt 1/2)
03:58:56.317 Refreshing due to a 401 (attempt 1/2)
好像它是从内部serviceName记录的:“appengine.googleapis.com”
部署的应用程序从GCS读取一些文件,并使用google pubsub发布一些计算的指标 . 我使用谷歌客户端API库,它使用凭据进行身份验证 .
credentials = GoogleCredentials.get_application_default()
if credentials.create_scoped_required():
credentials = credentials.create_scoped(['https://www.googleapis.com/auth/devstorage.read_only)
http = httplib2.Http()
credentials.authorize(http)
return discovery.build('storage', 'v1', http=http)
pubsub的类似片段也是如此 . 有任何人遇到类似的问题,其中请求似乎永远停留在显示401状态代码的信息日志 . 不确定为什么请求不会超时并导致失败 . 任何变通方法?
1 回答
401是未经授权的错误,这意味着OAuth承载令牌不再有效,需要使用刷新令牌刷新 . 您解释的时间轴与the duration of the bearer tokens匹配 .
我会使用cloud idiomatic libraries,或者如果您使用的是GAE标准,the appengine libraries directly . 这些库本身处理身份验证(包括在令牌过期时刷新令牌),并包含在App Engine中使用的进一步优化 .