To complete the get_auth_token() function in the script to obtain a valid authentication token using HTTP Basic Authentication, you need to use the requests library correctly. The correct approach involves using the requests.post() method with the HTTPBasicAuth function.
A. resp = requests.post(url, auth=HTTPBasicAuth(DNAC_USER, DNAC_PASSWORD)) token = resp.json()['Token'] return token
Correct. This option uses requests.post() and HTTPBasicAuth properly. It retrieves the token from the JSON response.
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
Incorrect. This option uses http.post(), which is incorrect.
References:
requests - HTTP for Humans
Cisco DNA Center Platform