Skip to content

Commit

Permalink
manubot#337 hunting requests without timeout.
Browse files Browse the repository at this point in the history
  • Loading branch information
xihh87 committed Jul 28, 2022
1 parent 226884a commit 74214f4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions manubot/cite/curie/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"synonyms",
}


default_timeout = 3
bioregistry_path = pathlib.Path(__file__).parent.joinpath("bioregistry.json")


Expand Down Expand Up @@ -111,7 +111,7 @@ def _download_bioregistry() -> None:
import requests

url = "https://github.com/biopragmatics/bioregistry/raw/main/exports/registry/registry.json"
response = requests.get(url)
response = requests.get(url, timeout=default_timeout)
response.raise_for_status()
results = response.json()
assert isinstance(results, dict)
Expand Down
4 changes: 3 additions & 1 deletion manubot/process/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from typing import Optional
from urllib.parse import urljoin

default_timeout = 3


def get_header_includes(variables: dict) -> str:
"""
Expand Down Expand Up @@ -160,7 +162,7 @@ def get_manuscript_urls(html_url: Optional[str] = None) -> dict:
return urls
urls["html_url_versioned"] = urljoin(html_url, "v/{commit}/".format(**ci_params))
urls["pdf_url_versioned"] = urljoin(urls["html_url_versioned"], "manuscript.pdf")
response = requests.head(html_url, allow_redirects=True)
response = requests.head(html_url, allow_redirects=True, timeout=default_timeout)
if not response.ok:
logging.warning(
"html_url is not web accessible. "
Expand Down
4 changes: 3 additions & 1 deletion manubot/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import typing
from types import ModuleType

default_timeout = 3

if typing.TYPE_CHECKING:
# allow type annotations of lazy-imported packages
import yaml
Expand Down Expand Up @@ -85,7 +87,7 @@ def read_serialized_data(path: str):
suffixes = set(path_obj.suffixes)
if is_http_url(path_str):
headers = {"User-Agent": get_manubot_user_agent()}
response = requests.get(path_str, headers=headers)
response = requests.get(path_str, headers=headers, timeout=default_timeout)
if not suffixes & supported_suffixes:
# if URL has no supported suffixes, evaluate suffixes of final redirect
suffixes = set(pathlib.Path(response.url).suffixes)
Expand Down

0 comments on commit 74214f4

Please sign in to comment.