Skip to content

Commit

Permalink
Fix: Compatibility with urllib3>=2 (#40)
Browse files Browse the repository at this point in the history
* Build: Pin urllib3<2

* Fix: Actually fix the issue properly
  • Loading branch information
adrien-berchet authored Nov 14, 2023
1 parent 632e9e4 commit aef37f1
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions morphapi/utils/webqueries.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
import time

import requests
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.ssl_ import create_urllib3_context

from morphapi.utils.data_io import connected_to_internet

mouselight_base_url = "https://ml-neuronbrowser.janelia.org/"
CIPHERS = ":HIGH:!DH:!aNULL"


class NoDhAdapter(HTTPAdapter):
"""A TransportAdapter that disables DH cipher in Requests."""

def init_poolmanager(self, *args, **kwargs):
context = create_urllib3_context(ciphers=CIPHERS)
kwargs["ssl_context"] = context
return super(NoDhAdapter, self).init_poolmanager(*args, **kwargs)


def request(url, verify=True):
Expand All @@ -19,14 +31,9 @@ def request(url, verify=True):
"You need to have an internet connection to send requests."
)

try:
_DEFAULT_CIPHERS = requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS
requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS = (
_DEFAULT_CIPHERS + ":HIGH:!DH:!aNULL"
)
response = requests.get(url, verify=verify)
finally:
requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS = _DEFAULT_CIPHERS
session = requests.Session()
session.mount("https://", NoDhAdapter())
response = session.get(url)

if response.ok:
return response
Expand Down

0 comments on commit aef37f1

Please sign in to comment.