import requests base_server = "192.168.50.60" keycloak_base_url = f"https://{base_server}/auth" # Replace with your Keycloak server URL zvm_api_url = f"https://{base_server}/v1" realm = "zerto" # Replace with your Keycloak realm name client_id = "api-script" client_secret = "fcYMFuA5TkIUwp6b3hDUxim0f32z8erk" # Replace with your client's secret key token_url = f"{keycloak_base_url}/realms/{realm}/protocol/openid-connect/token" data = { "grant_type": "client_credentials", "client_id": client_id, "client_secret": client_secret, } # Disable SSL certificate verification (use with caution) response = requests.post(token_url, data=data, verify=False) if response.status_code == 200: access_token = response.json()["access_token"] print("Authentication successful. Access token:", access_token) else: print("Authentication failed. Status code:", response.status_code) print("Error message:", response.text) uri = zvm_api_url + "/vpgs" print(uri) headers = { "Authorization": f"Bearer {access_token}", "accept": "application/json" } # Make a POST request to the token URL with the data headers=headers, response = requests.get(uri, headers=headers, verify=False) # Check if the request was successful (HTTP status code 200) if response.status_code == 200: # Parse the response JSON to get the access token print(response.text) else: print("Status code:", response.status_code) print("Error message:", response)