200-901 · Question #280
Refer to the exhibit. A developer creates a script to obtain a list of devices by using the Cisco DNA Center API. The remote server authorizes the request only if an authentication token is supplied i
The correct answer is A. resp = requests.post(url, auth=HTTPBasicAuth(DNAC_USER, DNAC_PASSWORD)) token =. The Cisco DNA Center API requires HTTP Basic Authentication to obtain an auth token. The correct library is 'requests' (not 'http', which is a lower-level stdlib module). Answer A uses 'requests.post()' with 'HTTPBasicAuth(DNAC_USER, DNAC_PASSWORD)', which is the explicit, standa
Question
Refer to the exhibit. A developer creates a script to obtain a list of devices by using the Cisco DNA Center API. The remote server authorizes the request only if an authentication token is supplied in the headers. A function named get_auth_token() must retrieve a valid token by using HTTP Basic Authentication. Which code must be added to complete the get_auth_token() function?
Exhibit
Options
- Aresp = requests.post(url, auth=HTTPBasicAuth(DNAC_USER, DNAC_PASSWORD)) token =
- Bresp = requests.post(url, auth=(DNAC_USER, DNAC_PASSWORD)) token = resp.json ()['Token']
- Cresp = http.post(url, auth=HTTPBasicAuth(DNAC_USER, DNAC_PASSWORD)) token =
- Dresp = http.post(url, auth=(DNAC_USER, DNAC_PASSWORD)) token = resp.json()['Token']
How the community answered
(37 responses)- A76% (28)
- B16% (6)
- C3% (1)
- D5% (2)
Explanation
The Cisco DNA Center API requires HTTP Basic Authentication to obtain an auth token. The correct library is 'requests' (not 'http', which is a lower-level stdlib module). Answer A uses 'requests.post()' with 'HTTPBasicAuth(DNAC_USER, DNAC_PASSWORD)', which is the explicit, standard way to pass Basic Auth credentials using the requests library. Answer B also uses 'requests.post' but passes auth as a tuple - while functionally equivalent in Python, the exam expects the explicit HTTPBasicAuth form. Answers C and D are incorrect because 'http.post()' is not a valid method in Python's http module. The token is then extracted from the JSON response using resp.json()['Token'], which matches the DNA Center API response schema.
Topics
Community Discussion
No community discussion yet for this question.
