catch ConnectionError on HEAD

This commit is contained in:
Justin Mathews 2021-06-07 16:50:42 -04:00
parent 84d4a5b97a
commit 57c866caf1
2 changed files with 4 additions and 14 deletions

View File

@ -26,7 +26,7 @@ from urllib.parse import unquote, urlparse
from docutils import nodes from docutils import nodes
from docutils.nodes import Element from docutils.nodes import Element
from requests import Response from requests import Response
from requests.exceptions import HTTPError, TooManyRedirects from requests.exceptions import HTTPError, TooManyRedirects, ConnectionError
from sphinx.application import Sphinx from sphinx.application import Sphinx
from sphinx.builders.dummy import DummyBuilder from sphinx.builders.dummy import DummyBuilder
@ -460,7 +460,7 @@ class HyperlinkAvailabilityCheckWorker(Thread):
config=self.config, auth=auth_info, config=self.config, auth=auth_info,
**kwargs) **kwargs)
response.raise_for_status() response.raise_for_status()
except (HTTPError, TooManyRedirects) as err: except (HTTPError, TooManyRedirects, ConnectionError) as err:
if isinstance(err, HTTPError) and err.response.status_code == 429: if isinstance(err, HTTPError) and err.response.status_code == 429:
raise raise
# retry with GET request if that fails, some servers # retry with GET request if that fails, some servers

View File

@ -579,16 +579,6 @@ def test_limit_rate_bails_out_after_waiting_max_time(app):
@pytest.mark.sphinx('linkcheck', testroot='linkcheck-connection-error-on-http-head', freshenv=True) @pytest.mark.sphinx('linkcheck', testroot='linkcheck-connection-error-on-http-head', freshenv=True)
def test_get_after_head_raises_connection_error(app): def test_get_after_head_raises_connection_error(app):
class InternalServerErrorHandler(http.server.BaseHTTPRequestHandler): app.build()
def do_GET(self):
self.send_error(500, "Internal Server Error")
with http_server(InternalServerErrorHandler):
app.build()
content = (app.outdir / 'output.txt').read_text() content = (app.outdir / 'output.txt').read_text()
assert "broken" not in content assert not content
# assert content == (
# "index.rst:1: [broken] http://localhost:7777/#anchor: "
# "500 Server Error: Internal Server Error "
# "for url: http://localhost:7777/\n"
# )