2017-08-15 91 views
0

我使用的訓練者應用下面的代碼,它運行在雲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的本地計算機上運行同一段代碼,沒有任何問題。 請讓我知道,如果我在這裏失去了一些東西。

回答

0

你不介意嘗試的oauth2client.client.GoogleCredentials作爲指定here

通過 credentials = GoogleCredentials.get_application_default()

build()方法,然後獲取證書將採取注射針對給定服務的適當範圍的照顧,儘管該方法create_scoped可以用來明確地做到這一點。

我不能完全肯定這會爲你工作,但它是朝着正確方向邁出的一步。

使用ADC絕對應該工作...但最終你可能要爲你的密鑰訪問更好的審計日誌服務帳戶運行。