From f314245aa5edcbf12e97fe1c9266acbca869169d Mon Sep 17 00:00:00 2001 From: Jeroen Demeyer Date: Tue, 14 Mar 2017 18:56:18 +0100 Subject: [PATCH] Allow running Sphinx without ssl --- sphinx/util/requests.py | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/sphinx/util/requests.py b/sphinx/util/requests.py index 674e00900..5c3cdb419 100644 --- a/sphinx/util/requests.py +++ b/sphinx/util/requests.py @@ -36,30 +36,34 @@ except ImportError: # for requests < 2.4.0 InsecureRequestWarning = None -# try to load requests[security] +# try to load requests[security] (but only if SSL is available) try: - pkg_resources.require(['requests[security]']) -except (pkg_resources.DistributionNotFound, - pkg_resources.VersionConflict): import ssl - if not getattr(ssl, 'HAS_SNI', False): - # don't complain on each url processed about the SSL issue - requests.packages.urllib3.disable_warnings( - requests.packages.urllib3.exceptions.InsecurePlatformWarning) +except ImportError: + pass +else: + try: + pkg_resources.require(['requests[security]']) + except (pkg_resources.DistributionNotFound, + pkg_resources.VersionConflict): + if not getattr(ssl, 'HAS_SNI', False): + # don't complain on each url processed about the SSL issue + requests.packages.urllib3.disable_warnings( + requests.packages.urllib3.exceptions.InsecurePlatformWarning) + warnings.warn( + 'Some links may return broken results due to being unable to ' + 'check the Server Name Indication (SNI) in the returned SSL cert ' + 'against the hostname in the url requested. Recommended to ' + 'install "requests[security]" as a dependency or upgrade to ' + 'a python version with SNI support (Python 3 and Python 2.7.9+).' + ) + except pkg_resources.UnknownExtra: warnings.warn( 'Some links may return broken results due to being unable to ' 'check the Server Name Indication (SNI) in the returned SSL cert ' 'against the hostname in the url requested. Recommended to ' - 'install "requests[security]" as a dependency or upgrade to ' - 'a python version with SNI support (Python 3 and Python 2.7.9+).' + 'install requests-2.4.1+.' ) -except pkg_resources.UnknownExtra: - warnings.warn( - 'Some links may return broken results due to being unable to ' - 'check the Server Name Indication (SNI) in the returned SSL cert ' - 'against the hostname in the url requested. Recommended to ' - 'install requests-2.4.1+.' - ) useragent_header = [('User-Agent', 'Mozilla/5.0 (X11; Linux x86_64; rv:25.0) Gecko/20100101 Firefox/25.0')]