From fcaeaf539cb913fa7c0e076e34e48f1e37ccf545 Mon Sep 17 00:00:00 2001 From: ClosedPort22 <44864697+ClosedPort22@users.noreply.github.com> Date: Sat, 11 Mar 2023 21:36:37 +0800 Subject: [PATCH] [downloader:http] handle exceptions while consuming content --- docs/configuration.rst | 2 +- gallery_dl/downloader/http.py | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index c88f8eb1..a64322d8 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -3617,7 +3617,7 @@ Description downloader.http.consume-content ---------------------------------- +------------------------------- Type ``bool`` Default diff --git a/gallery_dl/downloader/http.py b/gallery_dl/downloader/http.py index 30b59714..59cd0ac0 100644 --- a/gallery_dl/downloader/http.py +++ b/gallery_dl/downloader/http.py @@ -296,8 +296,15 @@ class HttpDownloader(DownloaderBase): def release_conn(self, response): """Release connection back to pool by consuming response body""" - for _ in response.iter_content(self.chunk_size): - pass + try: + for _ in response.iter_content(self.chunk_size): + pass + except (RequestException, SSLError, OpenSSLError) as exc: + print() + self.log.debug( + "Unable to consume response body (%s); " + "closing the connection anyway", exc) + response.close() @staticmethod def receive(fp, content, bytes_total, bytes_start):