gcp - python sdk - get firewall



我正试图从GCP获得防火墙列表或只是获得特定的防火墙信息。我正在使用GCP Python SDK。我已经导入了所有必需的模块/包。我的其余代码工作得很好,但是我在从GCP环境获取信息或列出防火墙时遇到了问题。我使用python代码来获取防火墙信息,变量:project,credentials在脚本中定义。导入模块:from pprint import pprintfrom googleapiclient import discoveryfrom oauth2client.client import GoogleCredentials

service = discovery.build('compute', 'v1', credentials=credentials)
# Name of the firewall rule to return.
firewall = 'FW-name'  # TODO: Update placeholder value.
request = service.firewalls().get(project=project, firewall=firewall)
response = request.execute()
# TODO: Change code below to process the `response` dict:
pprint(response)

我仍然收到以下错误:ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1129)

我不认为SSL错误与列表防火墙代码有关。我刚刚测试并得到了一个响应,没有任何问题:

from googleapiclient import discovery
from oauth2client.client import GoogleCredentials
credentials = GoogleCredentials.get_application_default()
service = discovery.build('compute', 'v1', credentials=credentials)
# Name of the firewall rule to return.
firewall = 'default-allow-icmp'  # TODO: Update placeholder value.
request = service.firewalls().get(project="my-project-1", firewall=firewall)
response = request.execute()
# TODO: Change code below to process the `response` dict:
print(response)

反应:

{'id': '5299901251757818599', 'creationTimestamp': '2021-07-28T17:53:28.718-07:00', 'name': 'default-allow-icmp', 'description': 'Allow ICMP from anywhere', 'network': *redacted*}

检查您的代码,看看SSL可能来自哪里。

最新更新