mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
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:
parent
fabe685638
commit
33732a3147
@ -20,7 +20,7 @@ from urllib.parse import unquote, urlparse
|
|||||||
|
|
||||||
from docutils import nodes
|
from docutils import nodes
|
||||||
from docutils.nodes import Node
|
from docutils.nodes import Node
|
||||||
from requests.exceptions import HTTPError
|
from requests.exceptions import HTTPError, TooManyRedirects
|
||||||
|
|
||||||
from sphinx.application import Sphinx
|
from sphinx.application import Sphinx
|
||||||
from sphinx.builders import Builder
|
from sphinx.builders import Builder
|
||||||
@ -177,7 +177,7 @@ class CheckExternalLinksBuilder(Builder):
|
|||||||
response = requests.head(req_url, config=self.app.config,
|
response = requests.head(req_url, config=self.app.config,
|
||||||
auth=auth_info, **kwargs)
|
auth=auth_info, **kwargs)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
except HTTPError:
|
except (HTTPError, TooManyRedirects):
|
||||||
# retry with GET request if that fails, some servers
|
# retry with GET request if that fails, some servers
|
||||||
# don't like HEAD requests.
|
# don't like HEAD requests.
|
||||||
response = requests.get(req_url, stream=True, config=self.app.config,
|
response = requests.get(req_url, stream=True, config=self.app.config,
|
||||||
|
Loading…
Reference in New Issue
Block a user