目前,我正在为 TF2 模型构建异步前端。现在它作为两个服务运行,第一个服务是扭曲服务,第二个服务是 TensorFlow 服务。
异步 Web 客户端用于异步查询模型。出于实际原因,我已将模型部署到 GCP AI Platform 中,并且我可以使用示例中的 python 代码从中获取数据,这没问题。
但问题是 Google API 客户端是同步的,我想使用异步客户端。因为据我所知,GCP 没有主动支持的异步客户端,所以我尝试直接使用 REST。TensorFlow 服务上的模型输入是相同的(我相信 GCP AI Platform 在内部使用 TensorFlow 服务)。
要执行异步调用,我需要:
我看到了一些例子:
import googleapiclient.discovery
credentials = service_account.Credentials.from_service_account_file(
'/path/to/key.json',
scopes=['https://www.googleapis.com/auth/cloud-platform'])
Run Code Online (Sandbox Code Playgroud)
但问题是credential.token,None所以我不能使用它。
所以我有一个问题:如何获得访问令牌以在其余请求中使用?
或者也许还有另一种更好的方法?
我已经看到以下问题:How to get access token from instance of google.oauth2.service_account.Credentials object? 但我认为这有点无关紧要。
python google-oauth google-cloud-platform tensorflow-serving