A penetration tester needs to test a very large number of URLs for public access. Given the following code snippet: 1 import requests 2 import pathlib 4 for url in pathlib.Path("urls.txt").read_text().split("\n"): 5 response = requests.get(url) 6 if response.status == 401: 7 print("URL accessible") Which of the following changes is required?
正解:A
Script Analysis: Line 1: import requests - Imports the requests library to handle HTTP requests. Line 2: import pathlib - Imports the pathlib library to handle file paths. Line 4: for url in pathlib.Path("urls.txt").read_text().split("\n"): - Reads the urls.txt file, splits its contents by newline, and iterates over each URL. Line 5: response = requests.get(url) - Sends a GET request to the URL and stores the response. Line 6: if response.status == 401: - Checks if the response status code is 401 (Unauthorized). Line 7: print("URL accessible") - Prints a message indicating the URL is accessible. Error Identification: The condition if response.status == 401: is incorrect for determining if a URL is publicly accessible. A 401 status code indicates that the resource requires authentication. Correct Condition: The correct condition should check for a 200 status code, which indicates that the request was successful and the resource is accessible. Corrected Script: Replace if response.status == 401: with if response.status_code == 200: to correctly identify publicly accessible URLs.