200-901 · Question #417
Drag and Drop Question Drag and drop the code from the bottom onto the box where the code is missing to authenticate with the Cisco DNA Center REST API by using basic authentication. Then generate a t
The correct answer is auth/basic; post; USERNAME. This question tests the ability to correctly complete Python code for authenticating with the Cisco DNA Center REST API using basic authentication to obtain a token.
Question
Drag and Drop Question Drag and drop the code from the bottom onto the box where the code is missing to authenticate with the Cisco DNA Center REST API by using basic authentication. Then generate a token for later use. Not all options are used. Answer:
Exhibit
Answer Area
Drag items
Correct arrangement
- auth/basic
- post
- USERNAME
Explanation
This question tests the ability to correctly complete Python code for authenticating with the Cisco DNA Center REST API using basic authentication to obtain a token.
Approach. The correct interaction involves dragging and dropping the appropriate options into the four blank fields in the Python code:
- First blank (after
AUTH_URL = '/dna/system/api/v1/'): Drag/auth/tokenhere. This is the specific REST API endpoint used by Cisco DNA Center to generate an authentication token. - Second blank (after
response = requests.): Dragposthere. Token generation, which involves creating a new session or credential, is typically done using the HTTP POST method. - Third blank (inside
auth=HTTPBasicAuth(before the comma): DragUSERNAMEhere. TheHTTPBasicAuthconstructor from therequests.authmodule takes the username as its first argument. - Fourth blank (inside
auth=HTTPBasicAuth(USERNAME,after the comma): DragPASSWORDhere. TheHTTPBasicAuthconstructor takes the password as its second argument.
This sequence correctly constructs the API call to perform basic authentication and retrieve a token from the Cisco DNA Center.
Common mistakes.
- common_mistake. Common mistakes include using incorrect HTTP methods or API endpoints, or misplacing the authentication credentials.
- 'get' instead of 'post': Using 'get' is incorrect because obtaining a token involves creating a new session, which requires the POST method, not the GET method used for retrieving data.
- 'auth/basic' instead of '/auth/token': 'auth/basic' is not the correct API endpoint for token generation; it might describe the type of authentication but not the specific resource path. The Cisco DNA Center API uses '/auth/token' to issue tokens.
- 'Token' instead of 'USERNAME' or 'PASSWORD': 'Token' is a key in the expected JSON response, not a variable holding authentication credentials. Placing 'Token' in the
HTTPBasicAuthconstructor would result in incorrect authentication arguments or a 'NameError' if 'Token' were not defined as a variable.
Concept tested. This question primarily tests knowledge of Python's requests library for making HTTP requests, understanding of REST API authentication (specifically HTTP Basic Authentication), and the common API endpoints and methods used for token generation, particularly in the context of Cisco DNA Center.
Topics
Community Discussion
No community discussion yet for this question.
