QuestionQ286

Understanding and Using APIs

Question Image

Refer to the exhibit. A developer creates a script to retrieve a list of devices using the Cisco DNA Center API. The remote server authorizes the request only when an authentication token is provided in the headers. A function named get_auth_token() must obtain a valid token by using HTTP Basic Authentication. Which code must be added to complete the get_auth_token() function?

  • A resp = requests.post(url, auth=HTTPBasicAuth(DNAC_USER, DNAC_PASSWORD)) token = resp.json()['Token'] return token
  • B resp = requests.post(url, auth=(DNAC_USER, DNAC_PASSWORD)) token = resp.json ()['Token'] return token
  • C resp = http.post(url, auth=HTTPBasicAuth(DNAC_USER, DNAC_PASSWORD)) token = resp.json()['Token'] return token
  • D resp = http.post(url, auth=(DNAC_USER, DNAC_PASSWORD)) token = resp.json()['Token'] return token
Explanation

Cisco DNA Center’s token endpoint uses an HTTP POST request with HTTP Basic Authentication. With Python’s requests library, requests.post(url, auth=HTTPBasicAuth(DNAC_USER, DNAC_PASSWORD)) performs that request, and the returned JSON token is obtained from the Token field and returned for use as the X-Auth-Token header value.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!