0

我在 Cloud ML 引擎中运行的培训应用程序中使用以下代码:

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 Cloud SDK 的本地计算机上运行相同的代码,没有任何问题。如果我在这里遗漏了什么,请告诉我。

4

1 回答 1

0

你介意试试这里oauth2client.client.GoogleCredentials指定的吗?

然后通过获取凭据 credentials = GoogleCredentials.get_application_default()

build()方法将负责为给定服务注入适当的范围,尽管该方法create_scoped可用于显式执行此操作。

我不完全确定这对你有用,但这是朝着正确方向迈出的一步。

使用 ADC 肯定可以工作......但最终您可能希望作为服务帐户运行,以便更好地审核您的密钥访问记录。

于 2017-08-17T13:59:42.383 回答