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.
Question
Exhibit
Answer Area
Drag items
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
HTTPBasicAuthand supplies a username/password pair ('admin', 'cisco'), which is specific to Basic Authentication, not token-based. Therefore, 'token' and 'HTTPTokenAuth' are incorrect for theauthparameter.
- Misplacing numeric '2': Placing '2' in any position other than the
timeoutparameter would be syntactically or logically incorrect, as it's a value for a specific parameter, not a variable name or an authentication object. - 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
Community Discussion
No community discussion yet for this question.
