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),
}
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())
my_url
andurl
are two different variables \$\endgroup\$