on master help sign in
[mod] upgrade requests to version 2.24.0. use ssl instead of pyopenssl.

requests 2.24.0 uses the ssl module except if it doesn't support SNI, in this case searx fallbacks to pyopenssl. searx logs a critical message and exit if the ssl modules doesn't support SNI and pyOpenSSL is not installed. searx logs a critical message and exit if the ssl version is older than 1.0.2. in requirements.txt, pyopenssl is still required to install searx as a fallback.

commit93f7f7eee2e843b3b3057b7854508c68c6432f3e authorAlexandre Flament <alex@al-f.net> dateTue 15 Sep 2020, 10:54 (6 years ago) parent21dbc7e
4 files changed+30−22
requirements.txt+3−3 searx/__init__.py−9 searx/poolrequests.py+27−3 searx/webapp.py−7
requirements.txt+3−3
@@ -1,12 +1,12 @@
1−certifi==2020.4.5.1
1+certifi==2020.6.20
22babel==2.7.0
33flask-babel==1.0.0
44flask==1.1.2
5−idna==2.9
5+idna==2.10
66jinja2==2.11.1
77lxml==4.5.0
88pygments==2.1.3
99pyopenssl==19.1.0
1010python-dateutil==2.8.0
1111pyyaml==5.3.1
12−requests[socks]==2.23.0
12+requests[socks]==2.24.0
searx/__init__.py−9
@@ -15,12 +15,10 @@ along with searx. If not, see < http://www.gnu.org/licenses/ >.
1515(C) 2013- by Adam Tauber, <asciimoo@gmail.com>
1616'''
1717
18−import certifi
1918import logging
2019from os import environ
2120from os.path import realpath, dirname, join, abspath, isfile
2221from io import open
23−from ssl import OPENSSL_VERSION_INFO, OPENSSL_VERSION
2422from yaml import safe_load
2523
2624
@@ -81,13 +79,6 @@ else:
8179
8280logger = logging.getLogger('searx')
8381logger.debug('read configuration from %s', settings_path)
84−# Workaround for openssl versions <1.0.2
85−# https://github.com/certifi/python-certifi/issues/26
86−if OPENSSL_VERSION_INFO[0:3] < (1, 0, 2):
87− if hasattr(certifi, 'old_where'):
88− environ['REQUESTS_CA_BUNDLE'] = certifi.old_where()
89− logger.warning('You are using an old openssl version({0}), please upgrade above 1.0.2!'.format(OPENSSL_VERSION))
90−
9182logger.info('Initialisation done')
9283
9384if 'SEARX_SECRET' in environ:
searx/poolrequests.py+27−3
@@ -1,9 +1,33 @@
1−import requests
2−
1+import sys
2+from time import time
33from itertools import cycle
44from threading import RLock, local
5+
6+import requests
7+
58from searx import settings
6−from time import time
9+from searx import logger
10+
11+
12+logger = logger.getChild('poolrequests')
13+
14+
15+try:
16+ import ssl
17+ if ssl.OPENSSL_VERSION_INFO[0:3] < (1, 0, 2):
18+ # https://github.com/certifi/python-certifi#1024-bit-root-certificates
19+ logger.critical('You are using an old openssl version({0}), please upgrade above 1.0.2!'
20+ .format(ssl.OPENSSL_VERSION))
21+ sys.exit(1)
22+except ImportError:
23+ ssl = None
24+if not getattr(ssl, "HAS_SNI", False):
25+ try:
26+ import OpenSSL # pylint: disable=unused-import
27+ except ImportError:
28+ logger.critical("ssl doesn't support SNI and the pyopenssl module is not installed.\n"
29+ "Some HTTPS connections will fail")
30+ sys.exit(1)
731
832
933class HTTPAdapterWithConnParams(requests.adapters.HTTPAdapter):
searx/webapp.py−7
@@ -78,13 +78,6 @@ from searx.plugins.oa_doi_rewrite import get_doi_resolver
7878from searx.preferences import Preferences, ValidationException, LANGUAGE_CODES
7979from searx.answerers import answerers
8080
81−# check if the pyopenssl package is installed.
82−# It is needed for SSL connection without trouble, see #298
83−try:
84− import OpenSSL.SSL # NOQA
85−except ImportError:
86− logger.critical("The pyopenssl package has to be installed.\n"
87− "Some HTTPS connections will fail")
8881
8982# serve pages with HTTP/1.1
9083from werkzeug.serving import WSGIRequestHandler