FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.15] gh-79638: Restore "Treat an unreachable robots.txt as disallow all" (GH-152525) by miss-islington · Pull Request #153107 · python/cpython · GitHub

Repository navigation

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

Filter by extension

Filter by extension .py  (1) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
10 changes: 9 additions & 1 deletion Lib/urllib/robotparser.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Back | FazBrowse Home | New Git URL