Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Lib/urllib/robotparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,17 @@ def read(self):
f = urllib.request.urlopen(self.url)
except urllib.error.HTTPError as err:
if err.code in (401, 403):
# If access to robot.txt has the status Unauthorized/Forbidden,
# then most likely this applies to the entire site.
self.disallow_all = True
elif err.code >= 400 and err.code < 500:
elif 400 <= err.code < 500:
# RFC 9309, Section 2.3.1.3: the crawler MAY access any
# resources on the server.
self.allow_all = True
elif 500 <= err.code < 600:
# RFC 9309, Section 2.3.1.4: the crawler MUST assume
# complete disallow.
self.disallow_all = True
err.close()
else:
raw = f.read()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Disallow all access in :mod:`urllib.robotparser` if the ``robots.txt`` file
is unreachable due to server or network errors.
Loading