谷歌云KMS:无法建立

问题描述:

我使用的训练者应用下面的代码,它运行在云ML引擎客户端对象:谷歌云KMS:无法建立

credentials, project = google.auth.default(scopes=['https://www.googleapis.com/auth/cloudkms']) 
kms_client = googleapiclient.discovery.build('cloudkms', 'v1', credentials=credentials) 

而且我发现了以下错误:

 File "/root/.local/lib/python2.7/site-packages/trainer/kms.py", line 110, in decrypt 
    kms_client = googleapiclient.discovery.build('cloudkms', 'v1', credentials=credentials) 
    File "/usr/local/lib/python2.7/dist-packages/oauth2client/util.py", line 135, in positional_wrapper 
    return wrapped(*args, **kwargs) 
    File "/usr/local/lib/python2.7/dist-packages/googleapiclient/discovery.py", line 210, in build 
    credentials=credentials) 
    File "/usr/local/lib/python2.7/dist-packages/oauth2client/util.py", line 135, in positional_wrapper 
    return wrapped(*args, **kwargs) 
    File "/usr/local/lib/python2.7/dist-packages/googleapiclient/discovery.py", line 341, in build_from_document 
    http = credentials.authorize(http) 
AttributeError: 'Credentials' object has no attribute 'authorize' 

我可以从安装了Google云SDK的本地计算机上运行同一段代码,没有任何问题。 请让我知道,如果我在这里失去了一些东西。

你不介意尝试的oauth2client.client.GoogleCredentials作为指定here

通过 credentials = GoogleCredentials.get_application_default()

build()方法,然后获取证书将采取注射针对给定服务的适当范围的照顾,尽管该方法create_scoped可以用来明确地做到这一点。

我不能完全肯定这会为你工作,但它是朝着正确方向迈出的一步。

使用ADC绝对应该工作...但最终你可能要为你的密钥访问更好的审计日志服务帐户运行。