350-201 Question 247
Select 2You are tasked with automating a task in the Security Operations Center (SOC) to retrieve the latest security events from a Cisco Secure Endpoint (formerly AMP for Endpoints) API and log them into a file. The provided Python script works but currently lacks error handling for API request failures. Which modification should you make to ensure the script handles HTTP request errors effectively?
- A
Add a try-except block around the API request to catch exceptions and log errors.
- B
Use a while loop to continuously retry the request until it succeeds, without any delay.
- C
Include a conditional check for the HTTP response status code and log an error if it indicates failure.
- D
Add a function to terminate the script immediately if the API request fails.
Show answer and explanation
Correct answers: A, C
Explanation
To ensure the security operations task is automated effectively, the script must handle API request failures gracefully. Using a try-except block allows the script to catch and handle exceptions, such as network errors, without crashing. Additionally, checking the HTTP response status code ensures the script can identify unsuccessful responses and log errors as needed. Combining these techniques ensures robust error handling while avoiding excessive retries or abrupt terminations.
- A. Correct.
This is correct because a try-except block is essential for catching runtime exceptions during the API request, such as connectivity issues or server errors. It allows the script to handle errors gracefully.
- B. Incorrect.
This is incorrect because a continuous retry without delay can lead to excessive API calls, potentially violating rate limits and causing unnecessary resource consumption.
- C. Correct.
This is correct because checking the HTTP response status code ensures the script can detect failed requests (e.g., 4xx or 5xx errors) and take appropriate actions, such as logging the failure.
- D. Incorrect.
This is incorrect because terminating the script immediately on an API request failure is not recommended. It prevents the script from attempting retries or handling errors in a meaningful way.