tester81
tester81

Reputation: 595

gcp - python sdk - get firewall

I am trying to get firewall list or just get specific firewall info from GCP. I am using GCP Python SDK. I have imported all required modules/packages. Rest of my code works fine, but I have problems with getting information or listing firewalls from my GCP environment. I am using python code to get firewall info, variables: project, credentials are defined in the script. Modules are imported: from pprint import pprint, from googleapiclient import discovery, from 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)

I am still receiving following error: ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1129)

Upvotes: 0

Views: 436

Answers (1)

CaioT
CaioT

Reputation: 2211

I don't think the SSL error is related to the list firewall code. I've just tested and got a response without any problems:

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)

Response:

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

Check your code to see where the SSL might be coming from.

Upvotes: 1

Related Questions