From d39729c279ef0bbd963676f1fafa299497c50226 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Thu, 21 Mar 2024 09:53:38 +0800 Subject: [PATCH] Remove the SSL hacking solution so it works with urllib3 2.x (#111) --- .github/workflows/tests.yml | 4 ++-- HinetPy/__init__.py | 1 + HinetPy/client.py | 15 ++------------- HinetPy/utils.py | 1 + HinetPy/win32.py | 1 + docs/changelog.rst | 5 ++++- setup.py | 3 +++ tests/test_client.py | 6 +++--- tests/test_utils.py | 1 + tests/test_win32.py | 1 + 10 files changed, 19 insertions(+), 19 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 15744af1..d686a03d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -18,7 +18,7 @@ jobs: max-parallel: 1 # Hinet doesn't allow parallel data request fail-fast: false matrix: - python-version: ["3.7", "3.10"] + python-version: ["3.7", "3.12"] os: [macos-latest, ubuntu-latest] steps: @@ -39,7 +39,7 @@ jobs: - name: Install dependencies run: | pip install -r requirements.txt - pip install pytest>=6.0 pytest-cov coverage[toml] codecov + pip install pytest>=6.0 pytest-cov coverage[toml] codecov setuptools python setup.py sdist --formats=zip pip install dist/* diff --git a/HinetPy/__init__.py b/HinetPy/__init__.py index 594764a1..f672c48d 100644 --- a/HinetPy/__init__.py +++ b/HinetPy/__init__.py @@ -16,6 +16,7 @@ >>> win32.extract_sac(data, ctable) >>> win32.extract_sacpz(ctable) """ + # pylint: disable=invalid-name from pkg_resources import get_distribution diff --git a/HinetPy/client.py b/HinetPy/client.py index 8c17f1cf..598c1faa 100644 --- a/HinetPy/client.py +++ b/HinetPy/client.py @@ -1,6 +1,7 @@ """ Client for requesting Hi-net waveform data and catalog. """ + import csv import json import logging @@ -26,18 +27,6 @@ ) from .win32 import merge -# Hacking solution for "ssl.SSLError: [SSL: DH_KEY_TOO_SMALL] dh key too small" error. -# Reference: https://stackoverflow.com/a/41041028 -requests.packages.urllib3.disable_warnings() -requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS += ":HIGH:!DH:!aNULL" -try: - requests.packages.urllib3.contrib.pyopenssl.util.ssl_.DEFAULT_CIPHERS += ( - ":HIGH:!DH:!aNULL" - ) -except AttributeError: - # no pyopenssl support used / needed / available - pass - # Setup the logger FORMAT = "[%(asctime)s] %(levelname)s: %(message)s" logging.basicConfig(level=logging.INFO, format=FORMAT, datefmt="%Y-%m-%d %H:%M:%S") @@ -1039,7 +1028,7 @@ def get_selected_stations(self, code): parser = _GrepTableData() parser.feed(self.session.get(self._STATION, timeout=self.timeout).text) stations = [] - for (i, text) in enumerate(parser.tabledata): + for i, text in enumerate(parser.tabledata): # If the target station, grep both lon and lat. if re.match(pattern, text): stations.append( diff --git a/HinetPy/utils.py b/HinetPy/utils.py index 12f62367..93a589d7 100644 --- a/HinetPy/utils.py +++ b/HinetPy/utils.py @@ -1,6 +1,7 @@ """ Utility functions. """ + import math import shutil from datetime import date, datetime diff --git a/HinetPy/win32.py b/HinetPy/win32.py index 2823e2e7..56cdab6c 100644 --- a/HinetPy/win32.py +++ b/HinetPy/win32.py @@ -1,6 +1,7 @@ """ Process seismic waveform data in win32 format. """ + import glob import logging import math diff --git a/docs/changelog.rst b/docs/changelog.rst index 2585b555..8ff5b79c 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -1,5 +1,8 @@ Changelog -========= +=========a + +0.7.2 (2024-03-21) +- Remove the hacking solution for SSL connection issue so it works well with urllib3 v2.x 0.7.1 (2022-07-08): - Fix bugs in `get_event_waveform` diff --git a/setup.py b/setup.py index 57b5ab07..43e066e6 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,7 @@ """ Build and install the project. """ + from setuptools import find_packages, setup NAME = "HinetPy" @@ -29,6 +30,8 @@ "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3 :: Only", "Topic :: Internet :: WWW/HTTP", "Topic :: Scientific/Engineering :: Physics", diff --git a/tests/test_client.py b/tests/test_client.py index e5e42047..f379b51a 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -254,15 +254,15 @@ def test_get_event_waveform(client): def test_get_station_list(client): stations = client.get_station_list("0101") - assert type(stations) == list + assert isinstance(stations, list) assert len(stations) >= 700 stations = client.get_station_list("0120") - assert type(stations) == list + assert isinstance(stations, list) assert len(stations) >= 120 stations = client.get_station_list("0131") - assert type(stations) == list + assert isinstance(stations, list) assert len(stations) >= 250 diff --git a/tests/test_utils.py b/tests/test_utils.py index cd481e54..85f7d9f6 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,6 +1,7 @@ """ Tests for utils.py. """ + from datetime import date, datetime import pytest diff --git a/tests/test_win32.py b/tests/test_win32.py index 07ce18a3..28a3e34d 100644 --- a/tests/test_win32.py +++ b/tests/test_win32.py @@ -1,6 +1,7 @@ """ Tests for win32.py """ + import filecmp import glob import os