首页 > 解决方案 > 获取服务版本的建议方法是什么

问题描述

在 flex env 中获取谷歌应用引擎中服务版本列表的最佳方法是什么?(来自 Python 3 中的服务实例)。我想使用服务帐户 json 密钥文件进行身份验证。我需要找到当前的默认版本(流量最多)。

有没有我可以使用的库googleapiclient.discovery,或者google.appengine.api.modules?或者我应该从头开始构建它并在apps.services.versions.list使用 oauth 时请求 REST api?我在谷歌文档中找不到任何信息.. https://cloud.google.com/appengine/docs/standard/python3/python-differences#cloud_client_libraries

标签: python-3.xgoogle-app-engine-pythonapp-engine-flexible

解决方案


最后我能够解决它。GAE 上的简单事情变成了大问题..

解决方案:我在GOOGLE_APPLICATION_CREDENTIALSenv 变量中设置了 service_account.json 的路径。然后你可以使用google.auth.default

from googleapiclient.discovery import build
import google.auth

creds, project = google.auth.default(scopes=['https://www.googleapis.com/auth/cloud-platform.read-only'])
service = build('appengine', 'v1', credentials=creds, cache_discovery=False)
data = service.apps().services().get(appsId=APPLICATION_ID, servicesId=SERVICE_ID).execute()
print data['split']['allocations']

返回值是分配字典,其中版本为键,流量百分比为值。一切顺利!


推荐阅读