Skip to content

Commit

Permalink
fix: add encoding spec to requests for some links.
Browse files Browse the repository at this point in the history
`requests.head` fails on some links due to an encoding issue. This
forces the accepted encoding to be simple to accomodate most servers.
  • Loading branch information
Yannick-Dayer committed Jul 25, 2024
1 parent 24aecfb commit c183323
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/auto_intersphinx/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,12 @@ def docurls_from_environment(package: str) -> dict[str, str]:
if k.startswith(("documentation, ", "Documentation, ")):
raw_addr = k.split(",", 1)[1].strip()
# Find the final address after eventual redirects.
redirected = requests.head(raw_addr, allow_redirects=True).url
addr = _ensure_webdir(redirected)
redirected = requests.head(
raw_addr,
allow_redirects=True,
headers={"Accept-Encoding": ""}, # Fixes issue on some links
)
addr = _ensure_webdir(redirected.url)
if requests.head(addr + "/objects.inv").ok:
try:
return {md["version"]: addr}
Expand Down Expand Up @@ -198,8 +202,12 @@ def docurls_from_pypi(package: str, max_entries: int) -> dict[str, str]:
addr = urls.get("Documentation") or urls.get("documentation")
if addr is not None:
# Find the final address after eventual redirects.
redirected = requests.head(addr, allow_redirects=True).url
addr = _ensure_webdir(redirected)
redirected = requests.head(
addr,
allow_redirects=True,
headers={"Accept-Encoding": ""}, # Fixes issue on some links
)
addr = _ensure_webdir(redirected.url)
if requests.head(addr + "/objects.inv").ok:
versions[data["info"]["version"]] = addr

Expand Down

0 comments on commit c183323

Please sign in to comment.