200-901 exam dumps

200-901 practice question 133 of 204

Cisco DevNet Associate. Associate level, Cisco. Free question with the correct answer and a full explanation.

200-901 Question 133

Single answer

You are tasked with creating a Python script to interact with a network device using a REST API. The script includes a section where you need to store the API base URL and authentication token for reuse throughout the script. Which approach should you take to define these variables correctly while adhering to best practices?

  1. A

    Define the API base URL and token as global variables at the top of the script.

  2. B

    Hardcode the API base URL and token directly into each function that requires them.

  3. C

    Store the API base URL and token in a configuration file and load them into variables within the script.

  4. D

    Prompt the user to input the API base URL and token each time the script is executed.

Show answer and explanation

Correct answer: C

Explanation

The best practice is to store sensitive information, such as API tokens and URLs, in a configuration file. This approach ensures the variables can be reused throughout the script without hardcoding them directly, improving maintainability and security. Configuration files can also be excluded from version control to protect sensitive data.

  • A. Incorrect.

    Defining the API base URL and token as global variables at the top of the script can expose sensitive information if the script is shared or stored in a public repository. It is not considered a secure practice.

  • B. Incorrect.

    Hardcoding the API base URL and token into each function leads to redundancy and makes the script difficult to maintain. Additionally, it can expose sensitive information.

  • C. Correct.

    Storing the API base URL and token in a configuration file and loading them into variables is a secure and reusable approach. It allows for better script maintainability and ensures sensitive information is not directly embedded in the script.

  • D. Incorrect.

    Prompting the user to input the API base URL and token each time the script is executed is inefficient and can lead to user errors. It is not practical for automation or scalable solutions.

Timed practice exam

Take a 200-901 practice test under exam conditions

75 questions in 120 minutes, drawn from this bank, with a score report and a per-question review when you finish.

Start timed exam