Which TWO Python standard library modules are commonly combined when a script needs to fetch web content (such as Junos REST API data) and parse the resulting payload? (Choose two)
Trap 1: yaml
yaml parses YAML documents, not the JSON payload a Junos REST API returns, so it cannot decode the response body. It is tempting because Junos configuration files are YAML-like, making yaml the right choice when parsing device configuration templates rather than REST responses.
Trap 2: socket
socket provides low-level TCP/IP primitives, leaving HTTP request framing, headers and TLS to be implemented manually, so it does not fetch web content as required. It is tempting because it underpins all network communication, making socket correct when writing a custom protocol client.
Trap 3: pickle
pickle deserialises Python object byte streams, so it cannot parse the JSON text a Junos REST API returns. It is tempting because it serialises and restores Python objects, making pickle correct when caching parsed data between script runs rather than handling web payloads.
- A
json
The json module parses the REST API payload returned by the fetch, converting JSON text into Python dictionaries for manipulation. Combined with urllib.request, which performs the HTTP retrieval, it satisfies the scenario's need to fetch and then parse Junos REST API data.
- B
yaml
Why it fails: yaml parses YAML documents, not the JSON payload a Junos REST API returns, so it cannot decode the response body. It is tempting because Junos configuration files are YAML-like, making yaml the right choice when parsing device configuration templates rather than REST responses.
- C
socket
Why it fails: socket provides low-level TCP/IP primitives, leaving HTTP request framing, headers and TLS to be implemented manually, so it does not fetch web content as required. It is tempting because it underpins all network communication, making socket correct when writing a custom protocol client.
- D
urllib.request
urllib.request opens the HTTP connection and retrieves the raw response body from the Junos REST endpoint. Paired with json, it covers the fetch half of the task: the module returns bytes that the parsing module then decodes. It satisfies the stem's requirement for fetching web content before parsing.
- E
pickle
Why it fails: pickle deserialises Python object byte streams, so it cannot parse the JSON text a Junos REST API returns. It is tempting because it serialises and restores Python objects, making pickle correct when caching parsed data between script runs rather than handling web payloads.