admin管理员组文章数量:1356849
In my fast api server, it subscribes to the google realtime developer notifications.
python version 3.12.7 "google-cloud-pubsub (>=2.29.0,<3.0.0)"
The subscriber can be successfully initialized as below:
# self.credentials is a dict from google service account credential json file
self.subscriber = pubsub_v1.SubscriberClient.from_service_account_info(
self.credentials)
and used like this:
self._streaming_pull_future = self.subscriber.subscribe(
self.subscription_path,
callback=callback,
flow_control=flow_control,
)
logger.info(f"Listening for messages on {self.subscription_path}")
while self._running:
try:
if self._streaming_pull_future.done():
break
await asyncio.sleep(1)
except asyncio.CancelledError:
break
The subscriber client can initialized, successfully pulling and ack the messages. However, after about 30 minute, it throw out the error:
Error in notification worker: 401 Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See . [reason: "ACCESS_TOKEN_EXPIRED"
domain: "googleapis"
metadata {
key: "service"
value: "pubsub.googleapis"
}
metadata {
key: "method"
value: "google.pubsub.v1.Subscriber.StreamingPull"
}
]
The error indicates the access token has timed out. I have several questions: Is there a way to initialize the subscriber client so that it can automatically refresh the token itself? If not, what is the good practice that developer explicitly refresh the token, pass it to the subscriber?
本文标签: pythonhow to properly refresh access token for google pubsubv1SubscriberClientStack Overflow
版权声明:本文标题:python - how to properly refresh access token for google pubsub_v1.SubscriberClient - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743976274a2570889.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论