Skip to content

Commit

Permalink
Add support for legacy SSL negotiation
Browse files Browse the repository at this point in the history
Ubuntu 22.04 has new OpenSSL, which is too strict.

Fix based on urllib3/urllib3#2653
  • Loading branch information
al42and authored and PierreMesure committed May 2, 2024
1 parent 41620d8 commit 77f3088
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion services/downloader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from concurrent.futures import as_completed
from requests.adapters import HTTPAdapter
from requests_futures.sessions import FuturesSession
from ssl import create_default_context, Purpose
from urllib3.util import Retry

FTIWS_URL = 'https://ftiws.ftiab.se/fti_ws/fti_ws.asmx?op={}'
Expand All @@ -15,10 +16,23 @@ def soap_envelope(query, xml_parameters):
</soap12:Body>
</soap12:Envelope>"""


class HttpAdapterWithLegacySsl(HTTPAdapter):

def __init__(self, **kwargs):
OP_LEGACY_SERVER_CONNECT = 4 # Available as ssl.OP_LEGACY_SERVER_CONNECT in Python 3.12
self.ssl_context = create_default_context(Purpose.SERVER_AUTH)
self.ssl_context.options |= OP_LEGACY_SERVER_CONNECT
super().__init__(**kwargs)

def init_poolmanager(self, *args, **kwargs):
HTTPAdapter.init_poolmanager(self, *args, ssl_context=self.ssl_context, **kwargs)


class Downloader(object):

def __init__(self):
adapter = HTTPAdapter(max_retries=Retry(total=10, backoff_factor=0.1))
adapter = HttpAdapterWithLegacySsl(max_retries=Retry(total=10, backoff_factor=0.1))

self.s = FuturesSession(max_workers=10)
self.s.mount('https://', adapter)
Expand Down

0 comments on commit 77f3088

Please sign in to comment.