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.
This commit is contained in:
Sebastien Besson 2020-08-17 09:23:37 +01:00
parent fabe685638
commit 33732a3147

View File

@ -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,