CompTIA

PT0-003 practice question 6

CompTIA PenTest+ · free question 6 of 20

Question

A penetration tester needs to test a very large number of URLs for public access. Given the following code snippet: ```python 1 import requests 2 import pathlib 3 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. The condition on line 6 Correct
  • B. The method on line 5
  • C. The import on line 1
  • D. The delimiter in line 3

Explanation

HTTP 401 means Unauthorized, so the script reports exactly the URLs that are not publicly accessible; the condition on line 6 must check for success instead, for example response.status_code == 200 (the Requests library exposes the code as status_code). requests.get on line 5 is the right method for fetching each URL, the requests import is needed, and splitting the file on newlines correctly yields one URL per line.

Practice the whole free set

Answer all 20 free PT0-003 questions with instant feedback, or unlock all 342 questions with Learn and Exam modes.