From 1a9d39f0e3b684166199d5ffc36ddd6becb5d73e Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Fri, 5 Apr 2024 21:43:58 +0800 Subject: [PATCH 1/2] Add the hacky solution for SSL: DH_KEY_TOO_SMALL error --- HinetPy/client.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/HinetPy/client.py b/HinetPy/client.py index dbf32a0c..4876226a 100644 --- a/HinetPy/client.py +++ b/HinetPy/client.py @@ -15,6 +15,9 @@ from multiprocessing.pool import ThreadPool import requests +from requests.adapters import HTTPAdapter +from urllib3 import PoolManager +from urllib3.util import create_urllib3_context from .header import NETWORK from .utils import ( @@ -33,6 +36,16 @@ logger = logging.getLogger(__name__) +# Hacking solution for "ssl.SSLError: [SSL: DH_KEY_TOO_SMALL] dh key too small" error. +# Reference: https://stackoverflow.com/a/76217135 +class AddedCipherAdapter(HTTPAdapter): + def init_poolmanager(self, connections, maxsize, block=False): + ctx = create_urllib3_context(ciphers=":HIGH:!DH:!aNULL") + self.poolmanager = PoolManager( + num_pools=connections, maxsize=maxsize, block=block, ssl_context=ctx + ) + + class BaseClient: """ Base client to login in the Hi-net website. @@ -168,6 +181,8 @@ def login(self, user, password): if len(password) > 12: logger.warning("Password longer than 12 characters may be truncated.") self.session = requests.Session() + self.session.mount(self._HINET, AddedCipherAdapter()) + self.session.mount(self._AUTH, AddedCipherAdapter()) self.session.get(self._AUTH, timeout=self.timeout) # get cookie resp = self.session.post( self._AUTH, From bc341ef9d3d782487c2ed8d3f1d50315f2fb8df5 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Fri, 5 Apr 2024 23:09:30 +0800 Subject: [PATCH 2/2] [skip ci] changelog --- docs/changelog.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index f9503696..9475eae1 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -1,6 +1,11 @@ Changelog ========= +0.8.2 (2024-04-05) +------------------ + +- Add the updated solution for the "ssl.SSLError: [SSL: DH_KEY_TOO_SMALL] dh key too small" error + 0.8.1 (2024-03-31) ------------------