'Client' object has no attribute 'authorize' in gcp.How 解决这个问题?
'Client' object has no attribute 'authorize' in gcp.How to solve this?
我正在删除 GKE 中的磁盘 cluster.I 我正在使用我的 JSON-key 凭据删除与特定集群关联的磁盘。
Python
from google.cloud import storage
from googleapiclient import discovery
from oauth2client.client import GoogleCredentials
credentials = storage.Client.from_service_account_json("json_key")
service = discovery.build('compute','v1',credentials=credentials)
project = #PROJECT-NAME#
zone = #ZONE-NAME#
disk = [#list of disks]
for i in disk:
request = service.disks().delete(project=project, zone=zone, disk=disk)
response = request.execute()
print(response)
执行时遇到错误 'Client' object has no attribute 'authorize'。我哪里出错了?
如何删除特定 cluster.I 的磁盘以及任何其他方法。
谢谢。
您可以按照 link 尝试使用 ServiceAccountCredentials
而不是存储,然后尝试以下示例:
from pprint import pprint
from googleapiclient import discovery
from oauth2client.client import GoogleCredentials
from oauth2client.service_account import ServiceAccountCredentials
credentials = ServiceAccountCredentials.from_json_keyfile_name(
'key.json',
scopes='https://www.googleapis.com/auth/cloud-platform')
service = discovery.build('compute', 'v1', credentials=credentials)
我正在删除 GKE 中的磁盘 cluster.I 我正在使用我的 JSON-key 凭据删除与特定集群关联的磁盘。
Python
from google.cloud import storage
from googleapiclient import discovery
from oauth2client.client import GoogleCredentials
credentials = storage.Client.from_service_account_json("json_key")
service = discovery.build('compute','v1',credentials=credentials)
project = #PROJECT-NAME#
zone = #ZONE-NAME#
disk = [#list of disks]
for i in disk:
request = service.disks().delete(project=project, zone=zone, disk=disk)
response = request.execute()
print(response)
执行时遇到错误 'Client' object has no attribute 'authorize'。我哪里出错了?
如何删除特定 cluster.I 的磁盘以及任何其他方法。
谢谢。
您可以按照 link 尝试使用 ServiceAccountCredentials
而不是存储,然后尝试以下示例:
from pprint import pprint
from googleapiclient import discovery
from oauth2client.client import GoogleCredentials
from oauth2client.service_account import ServiceAccountCredentials
credentials = ServiceAccountCredentials.from_json_keyfile_name(
'key.json',
scopes='https://www.googleapis.com/auth/cloud-platform')
service = discovery.build('compute', 'v1', credentials=credentials)