From eb68d4554482c164fb369629911cbf282154a7f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Mon, 18 Jul 2022 22:20:30 +0200 Subject: [PATCH] add global 'warnings' option (#2762) --- docs/configuration.rst | 11 +++++++++++ gallery_dl/extractor/common.py | 13 ++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index 38f1fce8..14ee1a7d 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -3748,6 +3748,17 @@ Description as signal handler for. +warnings +-------- +Type + ``string`` +Default + ``"default"`` +Description + The `Warnings Filter action `__ + used for (urllib3) warnings. + + pyopenssl --------- Type diff --git a/gallery_dl/extractor/common.py b/gallery_dl/extractor/common.py index 6ccae7ff..1b41101f 100644 --- a/gallery_dl/extractor/common.py +++ b/gallery_dl/extractor/common.py @@ -795,12 +795,23 @@ SSL_CIPHERS = { } +urllib3 = requests.packages.urllib3 + # detect brotli support try: - BROTLI = requests.packages.urllib3.response.brotli is not None + BROTLI = urllib3.response.brotli is not None except AttributeError: BROTLI = False +# set (urllib3) warnings filter +action = config.get((), "warnings", "default") +if action: + try: + import warnings + warnings.simplefilter(action, urllib3.exceptions.HTTPWarning) + except Exception: + pass +del action # Undo automatic pyOpenSSL injection by requests pyopenssl = config.get((), "pyopenssl", False)