Skip to main content
5 of 8
edited title
Reinderien
  • 71.1k
  • 5
  • 76
  • 256

Printing a JSON/HTTP response from a Cisco endpoint

Please check over my Python code for a HTTP GET operation using the requests library, and provide any potential pointers for improvement.

import requests

token = input()

payload={}

headers = {
    "Accept": "application/yang-data+json",
    "Content-Type": "application/yang-data+json",
    "Authorization": "Bearer {}".format(token),
}

my_url = "https://sandbox-xxxx.cisco.com/restconf/data/native/router/bgp"


try:
    response = requests.get(url, headers=headers, data=payload, verify=False, timeout=10)
except requests.exceptions.HTTPError as errh:
    print(f"An HTTP Error occured: {errh}")
except requests.exceptions.ConnectionError as errc:
    print(f"An Error Connecting to the API occured: {errc}")
except requests.exceptions.Timeout as errt:
    print(f"A Timeout Error occured: {errt}")
except requests.exceptions.RequestException as err:
    print(f"An Unknown Error occured: {err}")
else:
    print(response.status_code)
    print(response.json())