350-201 Question 242
Select 3You are tasked with analyzing a Python script used to automate the retrieval of security logs from a Cisco Secure Firewall. The script contains the following snippet:
import requests
url = 'https://firewall.example.com/api/logs'
headers = {'Authorization': 'Bearer <token>'}
response = requests.get(url, headers=headers)
if response.status_code == 200:
logs = response.json()
for log in logs:
print(log['timestamp'], log['event'])
elif response.status_code == 401:
print('Authentication failed: Invalid token')
else:
print('Error:', response.status_code)
Which of the following statements about the script's functionality are correct?
- A
The script uses the
requestslibrary to send a GET request to the firewall's API. - B
The script will raise an exception if the server responds with a 401 status code.
- C
The script retrieves logs in JSON format if the API responds with a status code of 200.
- D
The script outputs an error message for any non-200 or non-401 status codes.
- E
The script ensures secure communication by verifying the SSL certificate of the API endpoint.
Show answer and explanation
Correct answers: A, C, D
Explanation
This Python script is used to retrieve security logs from a Cisco Secure Firewall API. It uses the requests library to send a GET request, handles various HTTP status codes (200 for success, 401 for authentication failure, and others as generic errors), and processes the logs in JSON format. However, it does not explicitly address SSL certificate verification, which is a critical consideration in secure communications.
- A. Correct.
Correct. The script uses the
requests.get()function with a specified URL and headers to retrieve data from the firewall's API. - B. Incorrect.
Incorrect. The script handles a 401 status code explicitly and prints an authentication failure message. It does not raise an exception in this case.
- C. Correct.
Correct. The script processes the response as JSON if the status code is 200, as indicated by the
response.json()function. - D. Correct.
Correct. For any status code that is neither 200 nor 401, the script outputs an error message with the status code.
- E. Incorrect.
Incorrect. There is no explicit mention in the script of SSL certificate verification, and the
requestslibrary by default does not enforce certificate validation unless explicitly configured.