Skip to content

Commit

Permalink
add option to disable pyOpenSSL usage (#508)
Browse files Browse the repository at this point in the history
(pyOpenSSL is now disabled by default)
  • Loading branch information
mikf committed Dec 8, 2019
1 parent 5eb89b2 commit 15f9bb3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
10 changes: 10 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1683,6 +1683,16 @@ Description * ``true``: Update urllib3's default cipher list
=========== =====


pyopenssl
---------
=========== =====
Type ``bool``
Default ``false``
Description Use `pyOpenSSL <https://www.pyopenssl.org/en/stable/>`__-backed
SSL-support.
=========== =====



API Tokens & IDs
================
Expand Down
24 changes: 15 additions & 9 deletions gallery_dl/extractor/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 = (
Expand Down Expand Up @@ -508,3 +513,4 @@ class Extr(cls):
from requests.packages.urllib3.util import ssl_ # noqa
ssl_.DEFAULT_CIPHERS = ciphers
del ssl_
del ciphers
2 changes: 1 addition & 1 deletion test/test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 15f9bb3

Please sign in to comment.