Skip to content

Commit 1874755

Browse files
authored
improve(remote_images): handle connection error (#307)
2 parents df4abaa + ec27de5 commit 1874755

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

mkdocs_rss_plugin/util.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from mkdocs.structure.pages import Page
3131
from mkdocs.utils import get_build_datetime
3232
from requests import Session
33-
from requests.exceptions import HTTPError
33+
from requests.exceptions import ConnectionError, HTTPError
3434

3535
# package
3636
from mkdocs_rss_plugin.constants import MKDOCS_LOGGER_NAME, REMOTE_REQUEST_HEADERS
@@ -643,16 +643,20 @@ def get_remote_image_length(
643643
# first, try HEAD request to avoid downloading the image
644644
try:
645645
attempt += 1
646+
logger.debug(
647+
f"Get remote image length (attempt {attempt}/2) - "
648+
f"Sending {http_method} request to {image_url}"
649+
)
646650
req_response = self.req_session.request(
647651
method=http_method, url=image_url, verify=ssl_verify
648652
)
649653
req_response.raise_for_status()
650654
img_length = req_response.headers.get("content-length")
651-
except HTTPError as err:
655+
except (ConnectionError, HTTPError) as err:
652656
logger.debug(
653657
f"Remote image could not been reached: {image_url}. "
654-
f"Trying again with GET and disabling SSL verification. Attempt: {attempt}. "
655-
f"Trace: {err}"
658+
f"Trying again with {http_method} and disabling SSL verification. "
659+
f"Attempt: {attempt}/2. Trace: {err}"
656660
)
657661
if attempt < 2:
658662
return self.get_remote_image_length(

0 commit comments

Comments
 (0)