From 15f9bb3d14eedf3cabb2925d3f35bfe86149f367 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sun, 8 Dec 2019 21:21:00 +0100 Subject: [PATCH] add option to disable pyOpenSSL usage (#508) (pyOpenSSL is now disabled by default) --- docs/configuration.rst | 10 ++++++++++ gallery_dl/extractor/common.py | 24 +++++++++++++++--------- test/test_results.py | 2 +- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index 23a0d09fda..b4d7e6053b 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -1683,6 +1683,16 @@ Description * ``true``: Update urllib3's default cipher list =========== ===== +pyopenssl +--------- +=========== ===== +Type ``bool`` +Default ``false`` +Description Use `pyOpenSSL `__-backed + SSL-support. +=========== ===== + + API Tokens & IDs ================ diff --git a/gallery_dl/extractor/common.py b/gallery_dl/extractor/common.py index 025e1cbff7..a36a1d81ef 100644 --- a/gallery_dl/extractor/common.py +++ b/gallery_dl/extractor/common.py @@ -108,13 +108,7 @@ def request(self, url, *, method="GET", session=None, retries=None, cloudflare.cookies.update(self.category, (domain, cookies)) return response if cloudflare.is_captcha(response): - try: - import OpenSSL # noqa - except ImportError: - msg = " - Install 'pyOpenSSL' and try again" - else: - msg = "" - self.log.warning("Cloudflare CAPTCHA" + msg) + self.log.warning("Cloudflare CAPTCHA") msg = "'{} {}' for '{}'".format(code, response.reason, url) if code < 500 and code != 429 and code != 430: @@ -475,10 +469,21 @@ class Extr(cls): http.cookiejar.MozillaCookieJar.magic_re = re.compile( "#( Netscape)? HTTP Cookie File", re.IGNORECASE) -# Replace default cipher list of urllib3 to avoid Cloudflare CAPTCHAs + +# Undo automatic pyOpenSSL injection by requests +pyopenssl = config.get((), "pyopenssl", False) +if not pyopenssl: + try: + from requests.packages.urllib3.contrib import pyopenssl # noqa + pyopenssl.extract_from_urllib3() + except ImportError: + pass +del pyopenssl + + +# Replace urllib3's default cipher list to avoid Cloudflare CAPTCHAs ciphers = config.get((), "ciphers", True) if ciphers: - logging.getLogger("gallery-dl").debug("Updating urllib3 ciphers") if ciphers is True: ciphers = ( @@ -508,3 +513,4 @@ class Extr(cls): from requests.packages.urllib3.util import ssl_ # noqa ssl_.DEFAULT_CIPHERS = ciphers del ssl_ +del ciphers diff --git a/test/test_results.py b/test/test_results.py index eef5559d05..958e530d3a 100644 --- a/test/test_results.py +++ b/test/test_results.py @@ -21,7 +21,7 @@ "exhentai", "kissmanga", "mangafox", "dynastyscans", "nijie", "bobx", "archivedmoe", "archiveofsins", "thebarchive", "fireden", "4plebs", "sankaku", "idolcomplex", "mangahere", "readcomiconline", "mangadex", - "sankakucomplex", "warosu", "fuskator", + "sankakucomplex", "warosu", "fuskator", "patreon", } # temporary issues, etc.