From 57c866caf1b64a23d08436b49c5e23313ec68259 Mon Sep 17 00:00:00 2001 From: Justin Mathews Date: Mon, 7 Jun 2021 16:50:42 -0400 Subject: [PATCH] catch ConnectionError on HEAD --- sphinx/builders/linkcheck.py | 4 ++-- tests/test_build_linkcheck.py | 14 ++------------ 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/sphinx/builders/linkcheck.py b/sphinx/builders/linkcheck.py index 05e12c173..a3d2eb935 100644 --- a/sphinx/builders/linkcheck.py +++ b/sphinx/builders/linkcheck.py @@ -26,7 +26,7 @@ from urllib.parse import unquote, urlparse from docutils import nodes from docutils.nodes import Element from requests import Response -from requests.exceptions import HTTPError, TooManyRedirects +from requests.exceptions import HTTPError, TooManyRedirects, ConnectionError from sphinx.application import Sphinx from sphinx.builders.dummy import DummyBuilder @@ -460,7 +460,7 @@ class HyperlinkAvailabilityCheckWorker(Thread): config=self.config, auth=auth_info, **kwargs) 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: raise # retry with GET request if that fails, some servers diff --git a/tests/test_build_linkcheck.py b/tests/test_build_linkcheck.py index 810d5555e..9966d21be 100644 --- a/tests/test_build_linkcheck.py +++ b/tests/test_build_linkcheck.py @@ -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) def test_get_after_head_raises_connection_error(app): - class InternalServerErrorHandler(http.server.BaseHTTPRequestHandler): - def do_GET(self): - self.send_error(500, "Internal Server Error") - - with http_server(InternalServerErrorHandler): - app.build() + app.build() content = (app.outdir / 'output.txt').read_text() - assert "broken" not in content - # assert content == ( - # "index.rst:1: [broken] http://localhost:7777/#anchor: " - # "500 Server Error: Internal Server Error " - # "for url: http://localhost:7777/\n" - # ) + assert not content