200-901 · Question #492
200-901 Question #492: Real Exam Question with Answer & Explanation
The question requires filling in missing Python code segments to retrieve network interface data using RESTCONF, based on a provided solution which contains several technical inaccuracies.
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 Python script that allows an engineer to retrieve interface data. Not all options are used.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 Python script that allows an engineer to retrieve interface data. Not all options are used. Answer:
Explanation
The question requires filling in missing Python code segments to retrieve network interface data using RESTCONF, based on a provided solution which contains several technical inaccuracies.
Approach. Based on the provided solution image (Image 3), the correct interactions are as follows, although some choices are technically incorrect for a functional script:
-
Line 09 (Headers dictionary key): The solution places
Encodinginto the first empty box. WhileAcceptis the standard HTTP header for specifying the desired response media type (application/yang-data+jsonin this case), the provided solution usesEncoding. -
Line 15 (URL construction - IP address placeholder): The solution places
ipaddressinto the empty box within the f-string for the URL. Thedevicedictionary contains the actual IP under the key'ip'. For an f-string,{{device['ip']}}would correctly embed the IP address. Inserting the literal stringipaddressas shown in the solution would make the URL non-functional (e.g.,https://ipaddress:9443/...). However,ipaddressis presented as the chosen option. -
Line 22 (JSON parsing - Accessing interfaces): The solution places
device['ip']into the empty box for accessing the JSON response. According to theietf-interfacesYANG model, the list of interfaces is typically found under the key'interface'(singular) within theietf-interfaces:interfacescontainer (e.g.,response['ietf-interfaces:interfaces']['interface']). Usingdevice['ip'](the device's IP address string) as a key to access the interfaces list is technically incorrect and would likely result in aKeyErrorat runtime. -
Line 24 (For loop iterable): The solution places
devicesinto the empty box for theforloop iterable. The loop is intended to iterate over theinterfaces(plural) variable, which should hold the collection of interface objects retrieved from the API. The variabledevicesis not defined anywhere in the script and is not a valid iterable in this context. The correct choice from the options would beinterfaces.
Common mistakes.
- common_mistake. Several choices in the provided solution are technically incorrect and represent common pitfalls or design flaws in the question itself:
-
Using
Encodinginstead ofAcceptfor the header: The standard HTTP header to negotiate the content type that a client expects from a server isAccept.Encoding(orContent-Encoding/Accept-Encoding) relates to data compression, not the data format itself. A common mistake would be confusing these HTTP headers. -
Placing
ipaddressstring literal in the URL f-string instead ofdevice['ip']: The f-stringf"https://{{ }}:{{device['port']}}/"expects a Python expression in the{{ }}curly braces to dynamically insert a value. Placing the string literalipaddressresults in a non-functional URL. The correct way to insert the device's IP from the dictionary isdevice['ip']. -
Using
device['ip']as a key for JSON parsing (Line 22): Theietf-interfaces:interfacesYANG model typically structures its response such that the list of individual interfaces is under a key named'interface'(singular). Using the device's IP address (device['ip']) as a key to extract interface data is fundamentally incorrect and would fail at runtime. The common mistake here is not understanding the standard JSON structure for YANG data models. -
Using
devicesinstead ofinterfacesas the iterable for the loop (Line 24): Theforloop is meant to iterate over the collection of interfaces fetched from the API, which should be stored in theinterfacesvariable (plural) defined in line 22.devicesis an undefined variable and would cause aNameError. The common mistake is confusing variable names or not correctly identifying the intended collection for iteration.
Concept tested. The underlying technical concepts being tested include Python dictionary usage, f-string formatting for URL construction, HTTP headers (specifically Accept for RESTCONF API calls), JSON parsing and navigation based on YANG data models (ietf-interfaces), and basic Python loop constructs (for-loop) for data processing. The question also implicitly tests the ability to interact with RESTCONF APIs using the requests library.
Topics
Community Discussion
No community discussion yet for this question.