From 33732a31477bba2c91b2f072c50085b15d8c976f Mon Sep 17 00:00:00 2001 From: Sebastien Besson Date: Mon, 17 Aug 2020 09:23:37 +0100 Subject: [PATCH] Extend linkchecker GET fallback logic to handle Too Many Redirects Some websites will enter infinite redirect loops with HEAD requests. In this case, the GET fallback is ignored as the exception is of type TooManyRedirects and the link is reported as broken. This extends the except clause to retry with a GET request for such scenarios. --- sphinx/builders/linkcheck.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sphinx/builders/linkcheck.py b/sphinx/builders/linkcheck.py index 9b54afc7c..735e1738d 100644 --- a/sphinx/builders/linkcheck.py +++ b/sphinx/builders/linkcheck.py @@ -20,7 +20,7 @@ from urllib.parse import unquote, urlparse from docutils import nodes from docutils.nodes import Node -from requests.exceptions import HTTPError +from requests.exceptions import HTTPError, TooManyRedirects from sphinx.application import Sphinx from sphinx.builders import Builder @@ -177,7 +177,7 @@ class CheckExternalLinksBuilder(Builder): response = requests.head(req_url, config=self.app.config, auth=auth_info, **kwargs) response.raise_for_status() - except HTTPError: + except (HTTPError, TooManyRedirects): # retry with GET request if that fails, some servers # don't like HEAD requests. response = requests.get(req_url, stream=True, config=self.app.config,