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.
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.
- First blank (inside
dna_api_auth):response = ___________.post(...)- Thepostmethod is part of therequestslibrary in Python, used for making HTTP POST requests. Therefore, 'requests' is the correct option here. - Second blank (inside
list_dna_devices):data = ___________.json()- After making an HTTP GET request, therequests.get()call returns aresponseobject. To parse the JSON body from this response, the.json()method is called on theresponseobject. Therefore, 'response' is the correct option. - 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 isdna_api_auth. Thedna_api_authfunction takeshost,username, andpasswordas arguments. Therefore, 'dna_api_auth' is the correct option. - Fourth blank (outside functions, after
tokenassignment):___________(token)- After obtaining the token, the next step is to call the function that lists DNA devices, passing the obtained token. This function islist_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 therequestslibrary methods (requests.get,requests.post) that contains the server's reply, and on which the.json()method is called.
- Using 'json' for
data = ___________.json(). Thejsonmodule in Python is used for encoding/decoding JSON strings, butresponse.json()is a method of therequestslibrary's response object that directly parses the JSON content from the HTTP response. It's notjson.response()or a direct call to thejsonmodule here. - 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.
- 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_authorlist_dna_devices). Misplacing them shows a lack of understanding of Python syntax and therequestslibrary'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
Community Discussion
No community discussion yet for this question.