From 29b0277e6b8850796d04a443b95ac2379865bbb4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 1 Jul 2023 02:42:34 +0200 Subject: [PATCH] Continued: - fixed handling returned `data` dict - added some debug log messages --- fba/helpers/json.py | 4 ++-- fba/http/federation.py | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/fba/helpers/json.py b/fba/helpers/json.py index 9264f1b..9681e60 100644 --- a/fba/helpers/json.py +++ b/fba/helpers/json.py @@ -22,7 +22,7 @@ import requests logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) -def from_response(response: requests.models.Response) -> list: +def from_response(response: requests.models.Response) -> any: logger.debug("response[]='%s' - CALLED!", type(response)) if not isinstance(response, requests.models.Response): raise ValueError(f"Parameter response[]='{type(response)}' is not type of 'Response'") @@ -37,7 +37,7 @@ def from_response(response: requests.models.Response) -> list: logger.debug("data[]='%s' - EXIT!", type(data)) if not isinstance(data, list) and not isinstance(data, dict): - logger.debug("data[]='%s' is not wanted, wrapping into 'dict'", type(data)) + logger.warning("data[]='%s' is not wanted, wrapping into 'dict'", type(data)) data = {data} except json.decoder.JSONDecodeError as exception: diff --git a/fba/http/federation.py b/fba/http/federation.py index 79385ea..b50328d 100644 --- a/fba/http/federation.py +++ b/fba/http/federation.py @@ -446,6 +446,7 @@ def determine_software(domain: str, path: str = None) -> str: logger.debug("data[]='%s'", type(data)) if "exception" in data: # Continue raising it + logger.debug("data()=%d contains exception='%s' - raising ...", len(data), type(data["exception"])) raise data["exception"] elif "error_message" in data: logger.debug("Returned error_message during fetching nodeinfo: '%s',status_code=%d", data['error_message'], data['status_code']) @@ -458,14 +459,15 @@ def determine_software(domain: str, path: str = None) -> str: logger.warning("JSON response contains only a message: '%s'", data["message"]) instances.set_last_error(domain, data["message"]) return fetch_generator_from_path(domain) - elif "software" not in data or "name" not in data["software"]: + elif "json" not in data or "software" not in data["json"] or "name" not in data["json"]["software"]: logger.debug("JSON response from domain='%s' does not include [software][name], fetching / ...", domain) software = fetch_generator_from_path(domain) logger.debug("Generator for domain='%s' is: '%s'", domain, software) - elif "software" in data and "name" in data["software"]: - logger.debug("Found data[software][name] in JSON response") - software = data["software"]["name"] + elif "json" in data and "software" in data["json"] and "name" in data["json"]["software"]: + logger.debug("Found data[json][software][name] in JSON response") + software = data["json"]["software"]["name"] + logger.debug("software[%s]='%s'", type(software), software) if software is None: logger.debug("Returning None - EXIT!") return None -- 2.39.5