200-901 · Question #462
200-901 Question #462: Real Exam Question with Answer & Explanation
The question tests the ability to complete a Python script that uses the 'requests' library to interact with a RESTCONF API on a network device, requiring knowledge of Python imports, dictionary initialization, function returns, and JSON response parsing.
Question
Drag and Drop Question Drag and drop the code from the bottom onto the box where the code is missing to retrieve the RESTCONF running configuration for an interface named TwentyFiveGigabitEthernet 1/1/2. Not all options are used. Answer:
Explanation
The question tests the ability to complete a Python script that uses the 'requests' library to interact with a RESTCONF API on a network device, requiring knowledge of Python imports, dictionary initialization, function returns, and JSON response parsing.
Approach. 1. The first blank, preceding 'requests, getpass', is used to import modules. The correct keyword for importing multiple modules is 'import'. Therefore, 'import requests, getpass' is the correct line. Drag 'import' to the first blank. 2. The second blank initializes the 'headers' variable, which is subsequently used as a dictionary (e.g., headers['Accept'] = ...). The correct way to initialize an empty dictionary is 'dict()'. Drag 'dict()' to the second blank. 3. The third blank is within the 'getRequest' function and immediately precedes 'requests.get(...)'. Since the function is designed to return the response from the HTTP request, as indicated by 'response = getRequest(url, creds)' later in the script, the 'return' keyword is required here. Drag 'return' to the third blank. 4. The fourth blank is part of 'print(response._____)'. Given that the 'Accept' header is set to 'application/yang-data+json', the server is expected to return JSON data. The 'requests' library's 'response' object provides the '.json()' method to parse the JSON content into a Python dictionary or list, which is ideal for structured data retrieval. Drag 'json' to the fourth blank.
Common mistakes.
- common_mistake. Using 'from' in the first blank is incorrect as 'from module import item' is for importing specific items from a module, not the module itself when listing multiple modules. Placing 'getpass' in any blank is wrong because it's a module name or a function within that module, not a Python keyword or an object to initialize a dictionary or return a response. Using 'text' instead of 'json()' for the final print statement would return the raw JSON string content, which is less useful for programmatic manipulation than the parsed Python object provided by 'json()'. Attempting to place 'return' for header initialization or response printing is syntactically incorrect and illogical given the function's purpose.
Concept tested. This question primarily tests Python programming for network automation, focusing on HTTP requests with the 'requests' library, RESTCONF API interaction, handling credentials, managing HTTP headers (specifically the 'Accept' header for content negotiation), and parsing JSON responses. It evaluates understanding of Python syntax for imports, dictionary initialization, function return values, and object methods.
Topics
Community Discussion
No community discussion yet for this question.