nerdexam
Cisco

350-901 · Question #21

Drag and drop the expressions from below onto the code to implement error handling. Not all options are used. Code context (from original source): ``python def get_dnac_wireless_profiles(): try: url…

This question tests knowledge of Python try/except error handling combined with parsing nested JSON responses from the Cisco DNA Center (DNAC) wireless profiles REST API using the requests library.

Understanding and Using APIs

Question

Drag and drop the expressions from below onto the code to implement error handling. Not all options are used. Code context (from original source):
def get_dnac_wireless_profiles():
 try:
 url = "https://sandboxdnac2.cisco.com/dna/intent/api/v1/" \
 "wireless/profile/<item 1>-ChicagoCampus1"
 print(token)
 payload = {}
 headers = {
 'x-auth-token': token
 }

 response = requests.request("GET", url, headers=headers, data = payload)
 response.raise_for_status()
 return response.json()[0][<item 2>]['<item 3>']
 except Exception as e:
 print(<item 6>)
Available options for drag and drop:
  • 0
  • ssidDetails
  • profileDetails
  • profileName
  • flexConnect
  • enableFlexConnect

Explanation

This question tests knowledge of Python try/except error handling combined with parsing nested JSON responses from the Cisco DNA Center (DNAC) wireless profiles REST API using the requests library.

Approach. The correct placements based on the available options and DNAC API response structure are: Item 2 = 'profileDetails' (the top-level key in the wireless profile JSON object), Item 3 = 'ssidDetails' (the nested key within profileDetails containing SSID configuration), and Item 6 = 'e' (the caught exception variable printed in the except block - likely missing from the PDF extraction). Item 1 in the URL is a profile-type prefix (e.g., 'Flex') making the full profile name 'Flex-ChicagoCampus1', which aligns with DNAC sandbox naming conventions. The pattern response.json()[0]['profileDetails']['ssidDetails'] correctly traverses the DNAC API response: index [0] gets the first profile object, then chains two dictionary lookups into the nested structure. The response.raise_for_status() call on the line above automatically raises an HTTPError for 4xx/5xx responses, which is then caught by the broad except Exception as e clause, making print(e) the appropriate handler.

Concept tested. Python try/except error handling with the requests library, specifically using response.raise_for_status() to surface HTTP errors, combined with navigating nested JSON dictionary structures returned by the Cisco DNAC wireless profile API (response.json()[0]['profileDetails']['ssidDetails']).

Reference. Cisco DevNet Associate (DEVASC 200-901) - Python error handling, requests library, and Cisco DNA Center Intent API for wireless profiles (https://developer.cisco.com/docs/dna-center/)

Topics

#Python#API Interaction#Cisco DNA Center#Error Handling

Community Discussion

No community discussion yet for this question.

Full 350-901 Practice