From 2ab913018d9dde0e9e35aea49f3c1a24ce83b526 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 13 Mar 2021 08:52:36 -0800 Subject: [PATCH] Use get_data helper when executing searches --- bookwyrm/connectors/abstract_connector.py | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/bookwyrm/connectors/abstract_connector.py b/bookwyrm/connectors/abstract_connector.py index 9f31b337d..9d8a05e06 100644 --- a/bookwyrm/connectors/abstract_connector.py +++ b/bookwyrm/connectors/abstract_connector.py @@ -44,21 +44,10 @@ class AbstractMinimalConnector(ABC): if min_confidence: params["min_confidence"] = min_confidence - resp = requests.get( + data = get_data( "%s%s" % (self.search_url, query), params=params, - headers={ - "Accept": "application/json; charset=utf-8", - "User-Agent": settings.USER_AGENT, - }, ) - if not resp.ok: - resp.raise_for_status() - try: - data = resp.json() - except ValueError as e: - logger.exception(e) - raise ConnectorException("Unable to parse json response", e) results = [] for doc in self.parse_search_data(data)[:10]: @@ -234,11 +223,12 @@ def dict_from_mappings(data, mappings): return result -def get_data(url): +def get_data(url, params=None): """ wrapper for request.get """ try: resp = requests.get( url, + params=params, headers={ "Accept": "application/json; charset=utf-8", "User-Agent": settings.USER_AGENT,