From 6fd82b337f92835bf06140162040d76c05eb5214 Mon Sep 17 00:00:00 2001 From: James Addison Date: Sun, 16 Apr 2023 14:40:50 +0100 Subject: [PATCH] Fixup: do not close the response before anchor-checking has been performed --- sphinx/builders/linkcheck.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sphinx/builders/linkcheck.py b/sphinx/builders/linkcheck.py index 694b6fc2440..22aa2a58a3c 100644 --- a/sphinx/builders/linkcheck.py +++ b/sphinx/builders/linkcheck.py @@ -318,9 +318,9 @@ def check_uri() -> tuple[str, str, int]: # Read the whole document and see if #anchor exists response = requests.get(req_url, stream=True, config=self.config, auth=auth_info, **kwargs) - response.close() # no HTTP body reads required; close the response response.raise_for_status() found = check_anchor(response, unquote(anchor)) + response.close() # HTTP body reads complete; close the response if not found: raise Exception(__("Anchor '%s' not found") % anchor)