From: Scott Worley Date: Fri, 29 Dec 2023 06:48:17 +0000 (-0800) Subject: fetch: Send User-Agent header X-Git-Url: http://git.scottworley.com/paperdoorknob/commitdiff_plain/1e86dcaaf369d3d89f25437443d0905044216723?hp=a8a47f7846509d22b123f4ab9cfdd7e65ac0d32e fetch: Send User-Agent header --- diff --git a/fetch.py b/fetch.py index b99938c..151e2a9 100644 --- a/fetch.py +++ b/fetch.py @@ -14,6 +14,10 @@ import requests import requests_cache +_headers = { + 'User-Agent': 'paperdoorknob/0.0.1 (https://git.scottworley.com/paperdoorknob/)'} + + class Fetcher(ABC): @abstractmethod def fetch(self, url: str) -> bytes: @@ -27,7 +31,7 @@ class _SessionFetcher(Fetcher): self._timeout = timeout def fetch(self, url: str) -> bytes: - with self._session.get(url, timeout=self._timeout) as r: + with self._session.get(url, timeout=self._timeout, headers=_headers) as r: r.raise_for_status() return r.content @@ -44,7 +48,7 @@ class _CachingFetcher(Fetcher): self._cache_hit_count = 0 def fetch(self, url: str) -> bytes: - with self._session.get(url, timeout=self._timeout) as r: + with self._session.get(url, timeout=self._timeout, headers=_headers) as r: r.raise_for_status() self._request_count += 1 self._cache_hit_count += int(r.from_cache)