nerdexam
CiscoCisco

200-901 · Question #408

200-901 Question #408: Real Exam Question with Answer & Explanation

The question requires completing Python code to first authenticate and obtain a security token, then use that token to retrieve a list of network devices from an API, by dragging the correct function and object names into the code.

Cisco Platforms and Development

Question

Drag and Drop Question Refer to the exhibit. Drag and drop the code from the bottom onto the box where the code is missing to construct a request that generates a security token and gets a list of network devices. Not all options are used. Answer:

Explanation

The question requires completing Python code to first authenticate and obtain a security token, then use that token to retrieve a list of network devices from an API, by dragging the correct function and object names into the code.

Approach. The goal is to generate a security token and then get a list of network devices using an API. The provided Python code defines two functions for these tasks and then calls them sequentially.

  1. First blank (inside dna_api_auth): response = ___________.post(...) - The post method is part of the requests library in Python, used for making HTTP POST requests. Therefore, 'requests' is the correct option here.
  2. Second blank (inside list_dna_devices): data = ___________.json() - After making an HTTP GET request, the requests.get() call returns a response object. To parse the JSON body from this response, the .json() method is called on the response object. Therefore, 'response' is the correct option.
  3. Third blank (outside functions, assigning to token): token = ___________.api_auth(host, username, password) - This line is meant to call the authentication function defined earlier in the code, which is dna_api_auth. The dna_api_auth function takes host, username, and password as arguments. Therefore, 'dna_api_auth' is the correct option.
  4. Fourth blank (outside functions, after token assignment): ___________(token) - After obtaining the token, the next step is to call the function that lists DNA devices, passing the obtained token. This function is list_dna_devices, which is also defined earlier in the code. Therefore, 'list_dna_devices' is the correct option.

Common mistakes.

  • common_mistake. 1. Using 'reply' instead of 'response' for data = ___________.json(). While 'reply' is semantically similar to 'response', 'response' is the actual object name returned by the requests library methods (requests.get, requests.post) that contains the server's reply, and on which the .json() method is called.
  1. Using 'json' for data = ___________.json(). The json module in Python is used for encoding/decoding JSON strings, but response.json() is a method of the requests library's response object that directly parses the JSON content from the HTTP response. It's not json.response() or a direct call to the json module here.
  2. Confusing 'list_dna_devices' with 'list devices'. 'list_dna_devices' is the actual function name defined in the Python code, whereas 'list devices' is just a descriptive phrase and not a callable function.
  3. Incorrectly placing 'dna_api_auth' or 'requests' in the wrong blanks. Each blank corresponds to a specific context: calling a library method (requests.post), accessing a response object's method (response.json), or invoking a previously defined function (dna_api_auth or list_dna_devices). Misplacing them shows a lack of understanding of Python syntax and the requests library's usage.

Concept tested. API authentication (token generation), making HTTP POST and GET requests using the Python requests library, handling API responses (JSON parsing), and sequential program flow with function calls.

Topics

#API Requests#REST API Authentication#Network Device APIs#Code Construction

Community Discussion

No community discussion yet for this question.

Full 200-901 PracticeBrowse All 200-901 Questions