Skip to content

Commit 500de24

Browse files
committed
Added user-agent to pd.read_html to fix 403
1 parent 279cbb7 commit 500de24

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

min_versions.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,22 @@
88
from packaging.version import Version
99

1010

11+
HEADERS = {
12+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
13+
}
14+
15+
1116
def get_min_python_version():
1217
"""
1318
Find the minimum version of Python supported (i.e., not end-of-life)
1419
"""
1520
min_python = (
16-
pd.read_html("https://devguide.python.org/versions/")[0].iloc[-1].Branch
21+
pd.read_html(
22+
"https://devguide.python.org/versions/",
23+
storage_options=HEADERS,
24+
)[0]
25+
.iloc[-1]
26+
.Branch
1727
)
1828
return min_python
1929

@@ -25,7 +35,8 @@ def get_min_numba_numpy_version(min_python):
2535
"""
2636
df = (
2737
pd.read_html(
28-
"https://numba.readthedocs.io/en/stable/user/installing.html#version-support-information" # noqa
38+
"https://numba.readthedocs.io/en/stable/user/installing.html#version-support-information", # noqa
39+
storage_options=HEADERS,
2940
)[0]
3041
.dropna()
3142
.drop(columns=["Numba.1", "llvmlite", "LLVM", "TBB"])
@@ -81,12 +92,14 @@ def get_min_scipy_version(min_python, min_numpy):
8192
Determine the SciPy version compatibility
8293
"""
8394
colnames = pd.read_html(
84-
"https://docs.scipy.org/doc/scipy/dev/toolchain.html#numpy"
95+
"https://docs.scipy.org/doc/scipy/dev/toolchain.html#numpy",
96+
storage_options=HEADERS,
8597
)[1].columns
8698
converter = {colname: str for colname in colnames}
8799
df = (
88100
pd.read_html(
89101
"https://docs.scipy.org/doc/scipy/dev/toolchain.html#numpy",
102+
storage_options=HEADERS,
90103
converters=converter,
91104
)[1]
92105
.rename(columns=lambda x: x.replace(" ", "_"))

0 commit comments

Comments
 (0)