本文介绍了如何在Python中以编程方式获取Cloud ML服务帐户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
云ML说明显示了如何使用shell命令获取服务帐户.如何在Python中以编程方式执行此操作?例如在Datalab中?
The Cloud ML instructions show how to obtain the service account using shell commands. How can I do this programmatically in Python? e.g. in Datalab?
推荐答案
您可以使用Google Cloud的Python客户端库发出getConfig请求.
You can use Google Cloud's Python client libraries to issue the getConfig request.
from googleapiclient import discovery
from googleapiclient import http
from oauth2client.client import GoogleCredentials
credentials = GoogleCredentials.get_application_default()
ml_client = discovery.build(
'ml',
'v1beta1',
requestBuilder=http.HttpRequest,
credentials=credentials)
p = ml_client.projects()
config = p.getConfig(name="projects/my-project").execute()
SERVICE_ACCOUNT = config["serviceAccount"]
这篇关于如何在Python中以编程方式获取Cloud ML服务帐户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!