python-3.x - 获取服务版本的建议方法是什么
问题描述
在 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
解决方案
最后我能够解决它。GAE 上的简单事情变成了大问题..
解决方案:我在GOOGLE_APPLICATION_CREDENTIALS
env 变量中设置了 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']
返回值是分配字典,其中版本为键,流量百分比为值。一切顺利!
推荐阅读
- php - Wordpress 出现问题,在主目录中生成随机文件和代码
- angular - 无法在新电脑上使用 ionic - 无法为空白项目提供服务
- generative-adversarial-network - NiftyNet 中的 GAN 调节输入
- flutter - 用大视频慢摇咀嚼
- spring-boot - Dockerized Spring boot 应用程序连接到数据库 docker 映像
- spring - 获取给定 Spring Bean 的类注解
- sql - 尝试删除不存在的记录时使 SQL 查询失败
- ionic4 - 如何在ionic 4中仅显示一次同意页面
- c# - HANDLE 和 CRITICAL_SECTION 的 C# 编组
- angular - 如果在表中找不到数据,如何显示“未找到结果” - Angular 8