Skip to content

Commit

Permalink
Remove the SSL hacking solution so it works with urllib3 2.x (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
seisman authored Mar 21, 2024
1 parent 3f80485 commit d39729c
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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/*
Expand Down
1 change: 1 addition & 0 deletions HinetPy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
>>> win32.extract_sac(data, ctable)
>>> win32.extract_sacpz(ctable)
"""

# pylint: disable=invalid-name

from pkg_resources import get_distribution
Expand Down
15 changes: 2 additions & 13 deletions HinetPy/client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Client for requesting Hi-net waveform data and catalog.
"""

import csv
import json
import logging
Expand All @@ -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")
Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions HinetPy/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Utility functions.
"""

import math
import shutil
from datetime import date, datetime
Expand Down
1 change: 1 addition & 0 deletions HinetPy/win32.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Process seismic waveform data in win32 format.
"""

import glob
import logging
import math
Expand Down
5 changes: 4 additions & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Build and install the project.
"""

from setuptools import find_packages, setup

NAME = "HinetPy"
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
1 change: 1 addition & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Tests for utils.py.
"""

from datetime import date, datetime

import pytest
Expand Down
1 change: 1 addition & 0 deletions tests/test_win32.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Tests for win32.py
"""

import filecmp
import glob
import os
Expand Down

0 comments on commit d39729c

Please sign in to comment.