Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linkcheck builder: ensure error response is removed-from-scope before fallback request #11349

Closed
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
6 changes: 6 additions & 0 deletions sphinx/builders/linkcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ def check_uri() -> tuple[str, str, int]:
if not found:
raise Exception(__("Anchor '%s' not found") % anchor)
else:
fallback = False
try:
# try a HEAD request first, which should be easier on
# the server and the network
Expand All @@ -336,6 +337,11 @@ def check_uri() -> tuple[str, str, int]:
except (ConnectionError, HTTPError, TooManyRedirects) as err:
if isinstance(err, HTTPError) and err.response.status_code == 429:
raise
fallback = True
del err

# any err.response from the initial request is now out-of-scope
if fallback:
# retry with GET request if that fails, some servers
# don't like HEAD requests.
response = requests.get(req_url, stream=True,
Expand Down