350-201 Question 243
Single answerA network administrator is using a Python script to extract logs from a Cisco Secure Firewall via its REST API. Below is a snippet of the script:
import requests
url = "https://firewall/api/logs"
headers = {
"Authorization": "Bearer <access_token>",
"Content-Type": "application/json"
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
print(response.json())
else:
print("Error:", response.status_code)
What is the purpose of the response.json() method in the script?
- A
It sends a JSON-formatted request to the API endpoint.
- B
It parses the JSON response from the API into a Python dictionary.
- C
It verifies the status code of the API response.
- D
It converts the Python dictionary into a JSON string.
Show answer and explanation
Correct answer: B
Explanation
The response.json() method is used in Python scripts that interact with APIs to convert a JSON response from the server into a Python dictionary. This allows the script to easily process the data returned by the API. Understanding the use of such methods is essential for leveraging automation in cybersecurity tasks, such as extracting logs or managing configurations via REST APIs.
- A. Incorrect.
Incorrect. The
response.json()method does not send any request; it is used to handle the response data from the API. - B. Correct.
Correct. The
response.json()method parses the JSON response from the API and converts it into a Python dictionary for further use in the script. - C. Incorrect.
Incorrect. Verifying the status code is done using the
response.status_codeproperty, notresponse.json(). - D. Incorrect.
Incorrect. The
response.json()method works in the opposite direction; it converts JSON data into a Python dictionary, not the other way around.