Skip to main content
edited tags
Link
200_success
  • 145.6k
  • 22
  • 191
  • 480
edited tags
Link
200_success
  • 145.6k
  • 22
  • 191
  • 480
deleted 3 characters in body
Source Link

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_urlurl = "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())

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())

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())
edited title
Link
Reinderien
  • 71.1k
  • 5
  • 76
  • 256
Loading
added 76 characters in body
Source Link
Loading
added 256 characters in body
Source Link
Loading
It's not the afternoon (at least somewhere)
Source Link
Toby Speight
  • 88.3k
  • 14
  • 104
  • 327
Loading
Source Link
Loading