diff --git a/CHANGELOG.md b/CHANGELOG.md index de3bc2b..f03eaab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ * Don't crash loudly when fetching webfinger for Diaspora that does not contain XML. +* Add missing `response.raise_for_status()` call to the `fetch_document` network helper + when fetching with given URL. Error status was already being raised correctly when + fetching by domain and path. + ## [0.19.0] - 2019-12-15 ### Added diff --git a/federation/hostmeta/fetchers.py b/federation/hostmeta/fetchers.py index 6076761..538f4e2 100644 --- a/federation/hostmeta/fetchers.py +++ b/federation/hostmeta/fetchers.py @@ -73,7 +73,7 @@ def fetch_nodeinfo_document(host): return doc, status_code, error = fetch_document(url=url) - if status_code >= 300 and not doc: + if not doc: return try: doc = json.loads(doc) diff --git a/federation/utils/network.py b/federation/utils/network.py index 2dc2f74..2599e70 100644 --- a/federation/utils/network.py +++ b/federation/utils/network.py @@ -63,6 +63,7 @@ def fetch_document(url=None, host=None, path="/", timeout=10, raise_ssl_errors=T :arg path: Path without domain (defaults to "/") :arg timeout: Seconds to wait for response (defaults to 10) :arg raise_ssl_errors: Pass False if you want to try HTTP even for sites with SSL errors (default True) + :arg extra_headers: Optional extra headers dictionary to add to requests :returns: Tuple of document (str or None), status code (int or None) and error (an exception class instance or None) :raises ValueError: If neither url nor host are given as parameters """ @@ -80,6 +81,7 @@ def fetch_document(url=None, host=None, path="/", timeout=10, raise_ssl_errors=T try: response = requests.get(url, timeout=timeout, headers=headers) logger.debug("fetch_document: found document, code %s", response.status_code) + response.raise_for_status() return response.text, response.status_code, None except RequestException as ex: logger.debug("fetch_document: exception %s", ex)