nerdexam
Cisco

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

Understanding and Using APIs

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

200-901 question #280 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)
  • A
    76% (28)
  • B
    16% (6)
  • C
    3% (1)
  • D
    5% (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

#API Authentication#Python Requests Library#HTTP Basic Authentication#JSON Parsing

Community Discussion

No community discussion yet for this question.

Full 200-901 Practice