X-Git-Url: http://git.scottworley.com/paperdoorknob/blobdiff_plain/a8a47f7846509d22b123f4ab9cfdd7e65ac0d32e..1e86dcaaf369d3d89f25437443d0905044216723:/fetch.py 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)