-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_requests_example.py
More file actions
38 lines (29 loc) · 908 Bytes
/
api_requests_example.py
File metadata and controls
38 lines (29 loc) · 908 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#! /usr/bin/env python
"""
Learning Series: Network Programmability Basics
Module: Programming Fundamentals
Lesson: Python Part 3
Author: Hank Preston <hapresto@cisco.com>
api_requests_example.py
Illustrate the following concepts:
- Making REST API calls using requests library
- Intended to be entered into an interactive
interpreter
"""
import requests
from pprint import pprint
router = {"ip": "ios-xe-mgmt.cisco.com",
"port": "9443",
"user": "root",
"pass": "D_Vay!_10&"}
headers = {"Accept": "application/yang-data+json"}
u = "https://{}:{}/restconf/data/interfaces/interface=GigabitEthernet1"
u = u.format(router["ip"], router["port"])
r = requests.get(u,
headers = headers,
auth=(router["user"], router["pass"]),
verify=False)
pprint(r.text)
api_data = r.json()
interface_name = api_data["Cisco-IOS-XE-interfaces-oper:interface"]["name"]
print(interface_name)