200-901 exam dumps

200-901 practice question 85 of 204

Cisco DevNet Associate. Associate level, Cisco. Free question with the correct answer and a full explanation.

200-901 Question 85

Single answer

You are tasked with automating the retrieval of device information from a network using Cisco's RESTCONF API. The requirements specify that you must fetch interface details in JSON format from a device using Python. Which of the following code snippets correctly meets the requirements?

  1. A

    import requests url = 'https://device-ip/restconf/data/interfaces/interface' headers = {'Accept': 'application/json'} response = requests.get(url, headers=headers, auth=('username', 'password')) print(response.json())

  2. B

    import http.client conn = http.client.HTTPSConnection('device-ip') headers = {'Accept': 'application/json'} conn.request('GET', '/restconf/data/interfaces/interface', headers=headers) response = conn.getresponse() print(response.json())

  3. C

    import requests url = 'https://device-ip/restconf/data/interfaces/interface' headers = {'Content-Type': 'application/json'} response = requests.post(url, headers=headers, auth=('username', 'password')) print(response.json())

  4. D

    import requests url = 'https://device-ip/api/interfaces' headers = {'Accept': 'application/json'} response = requests.get(url, headers=headers, auth=('username', 'password')) print(response.text)

Show answer and explanation

Correct answer: A

Explanation

The correct code snippet must use the requests library to make a GET request to the correct RESTCONF endpoint (/restconf/data/interfaces/interface) with the appropriate headers to request JSON data. The response must then be parsed as JSON using response.json(). Option 1 satisfies all the requirements, while the other options either use incorrect methods, endpoints, or request types.

  • A. Correct.

    This is the correct answer. It uses the requests library to make a RESTCONF GET request to the appropriate endpoint for interfaces and includes the correct headers to request JSON data. The response is then parsed using response.json(), which meets the requirements.

  • B. Incorrect.

    This option uses the http.client library, which is more complex and less commonly used for REST APIs. Additionally, the .json() method is not available in the http.client library, making this code incorrect.

  • C. Incorrect.

    This option makes a POST request instead of a GET request, which does not match the requirement to fetch data. POST requests are typically used to create or update resources, not retrieve them.

  • D. Incorrect.

    This option uses an incorrect URL (/api/interfaces instead of /restconf/data/interfaces/interface) and prints response.text instead of parsing the JSON data. This does not meet the requirements.

Timed practice exam

Take a 200-901 practice test under exam conditions

75 questions in 120 minutes, drawn from this bank, with a score report and a per-question review when you finish.

Start timed exam