6.0 Automation
Python for Network Automation Practice Questions
Python scripting patterns for interacting with network device APIs.
One solved question, so you can see how these are marked
Given the Python variable device = {"hostname": "Router1", "interfaces": ["Gig1", "Gig2"]}, what command returns the string "Gig2"?
device["interfaces"][1]
device is a dictionary; "interfaces" returns the list ["Gig1", "Gig2"]. List indexing is zero-based, so index [1] yields "Gig2".
Every question in the set below is marked like this. The answers stay hidden until you pick one.
All 9 Python for Network Automation questions in this set
Answers and explanations appear when you work through the set above.
Which Python library provides a multi-vendor abstraction layer specifically tailored for network automation tasks across Cisco, Arista, and Juniper hardware?
- urllib3
- NAPALM
- Paramiko
- BeautifulSoup
Which parameter in Python's requests library disables TLS certificate verification for an HTTPS request?
- cert=None
- verify=False
- allow_redirects=False
- stream=True
In Python, which method from the standard json library converts a native Python dictionary object into a formatted JSON-encoded string?
- json.loads()
- json.dumps()
- json.load()
- json.JSONDecoder()
Given a Python dictionary object device = {"hostname": "Router1", "interfaces": ["Gig0/0", "Gig0/1"]}, what expression extracts the string "Gig0/1"?
- device["interfaces"][1]
- device.interfaces[1]
- device["interfaces"][2]
- device.get("interfaces")[2]
In Python network automation scripts using requests, how do you bypass TLS certificate validation for a controlled test against a self-signed device certificate?
- requests.get(url, verify=False)
- requests.get(url, cert=None)
- requests.get(url, allow_redirects=False)
- requests.get(url, stream=True)
Given the following JSON response assigned to Python variable resp: resp = {"response": [{"id": "1", "name": "Dist-Switch-1", "status": "REACHABLE"}]} Which Python syntax accurately extracts the status string "REACHABLE"?
- resp["response"][0]["status"]
- resp["response"]["status"]
- resp.get("response")["status"][0]
- resp.response.status
Which Python syntax snippet correctly executes an HTTP GET request with HTTP Basic Authentication using the popular requests module?
- requests.get('https://router/api', auth=('admin', 'Cisco123'))
- requests.get('https://router/api', params={'user': 'admin', 'pass': 'Cisco123'})
- requests.get('https://router/api', cert=('admin', 'Cisco123'))
- requests.post('https://router/api', data={'user': 'admin', 'pass': 'Cisco123'})
In Python scripting, what action is performed by calling the json.loads(string_data) method?
- Serializes a Python dictionary into a JSON-formatted string ready to send in a request body.
- Parses (deserializes) a JSON-formatted string into native Python dictionaries and lists.
- Downloads a remote JSON file over SSH and saves it as a local Python dictionary object.
- Deletes every key that matches the given string variable from a loaded JSON document.
When building automated Python scripts that interact with RESTful APIs, how should the application handle an HTTP status response code of 429 Too Many Requests?
- Terminate the script permanently and delete the local cache so the next run starts clean.
- Back off (honoring any Retry-After header) and retry with an exponentially growing delay.
- Immediately resend the same request in a tight loop until the server accepts one of them.
- Re-authenticate with the default admin credentials, since 429 means the token has expired.