nerdexam
Cisco

200-901 · Question #666

Drag and Drop Question Refer to the exhibit. Drag and drop the code snippets from the bottom onto the blanks in the Python script to retrieve a list of hosts using the Cisco DNA Center API. Not all…

The correct answer is 2; HTTPBasicAuth. The question tests the ability to correctly complete a Python script using the requests library to make an API call, specifically by filling in parameters for the response object, timeout, client certificates, and HTTP Basic authentication.

Understanding and Using APIs

Question

Drag and Drop Question Refer to the exhibit. Drag and drop the code snippets from the bottom onto the blanks in the Python script to retrieve a list of hosts using the Cisco DNA Center API. Not all options are used. Answer:

Exhibit

200-901 question #666 exhibit

Answer Area

Drag items

tokenresponse2HTTPTokenAuthHTTPBasicAuthcert

Correct arrangement

  • 2
  • HTTPBasicAuth

Explanation

The question tests the ability to correctly complete a Python script using the requests library to make an API call, specifically by filling in parameters for the response object, timeout, client certificates, and HTTP Basic authentication.

Approach. 1. First blank (before = requests.get(...)): The final line of the script response.status_code clearly indicates that the return value of the requests.get call is assigned to a variable named response. Thus, 'response' is dragged to the first blank. 2. Second blank (timeout=_______,): The timeout parameter in the requests.get method expects a numeric value representing seconds. Among the available options, '2' is the only numeric value suitable for a timeout. Thus, '2' is dragged to the second blank. 3. Third blank (before =('/etc/pki/tls/certs/client.pem', '/etc/pki/tls/certs/client.key'),): The requests library uses the cert parameter to specify client-side SSL certificates, which can be provided as a tuple containing the certificate and key file paths. The provided tuple matches this format. Thus, 'cert' is dragged to the third blank. 4. Fourth blank (auth=_______('admin', 'cisco'))): The script imports HTTPBasicAuth from requests.auth. The arguments ('admin', 'cisco') represent a username and password, which are used for HTTP Basic Authentication. The 'Authentication API' documentation also highlights 'Basic' authentication using username and password. Thus, 'HTTPBasicAuth' is dragged to the fourth blank.

Common mistakes.

  • common_mistake. 1. Using 'token' or 'HTTPTokenAuth' for authentication: While Cisco DNA Center does have token-based authentication, the provided Python script explicitly imports HTTPBasicAuth and supplies a username/password pair ('admin', 'cisco'), which is specific to Basic Authentication, not token-based. Therefore, 'token' and 'HTTPTokenAuth' are incorrect for the auth parameter.
  1. Misplacing numeric '2': Placing '2' in any position other than the timeout parameter would be syntactically or logically incorrect, as it's a value for a specific parameter, not a variable name or an authentication object.
  2. Misplacing 'cert': Assigning 'cert' to any other parameter (like the response variable or timeout) would be incorrect because it specifically refers to client-side SSL certificates as shown by the subsequent tuple of file paths.

Concept tested. Making HTTP GET requests using Python's requests library, understanding common parameters like timeout, cert for client-side SSL certificates, and auth for authentication, specifically implementing HTTP Basic Authentication using requests.auth.HTTPBasicAuth. It also tests the ability to interpret Python syntax for variable assignment and function calls.

Topics

#Python scripting#REST API#Cisco DNA Center API#requests library

Community Discussion

No community discussion yet for this question.

Full 200-901 Practice