From: Roland Häder Date: Sat, 15 Jul 2023 00:47:38 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=ac043304f73df0df0b990c77f3549a80e96e22fa;p=fba.git Continued: - init rows list - log type and length - check if 'domain' and 'severity' are part of 'block' dictionary --- diff --git a/fba/networks/mastodon.py b/fba/networks/mastodon.py index cc1f463..4b61902 100644 --- a/fba/networks/mastodon.py +++ b/fba/networks/mastodon.py @@ -158,6 +158,7 @@ def fetch_blocks(domain: str, nodeinfo_url: str) -> list: headers, (config.get("connection_timeout"), config.get("read_timeout")) ) + rows = list() logger.debug("data[]='%s'", type(data)) if "error_message" in data: @@ -165,7 +166,7 @@ def fetch_blocks(domain: str, nodeinfo_url: str) -> list: instances.set_last_error(domain, data) return blocklist elif "json" in data and "error" in data["json"]: - logger.warning("JSON API returned error message: '%s'", data['json']['error']) + logger.warning("JSON API returned error message: '%s'", data["json"]["error"]) instances.set_last_error(domain, data) return blocklist else: @@ -175,10 +176,12 @@ def fetch_blocks(domain: str, nodeinfo_url: str) -> list: logger.debug("Marking domain='%s' as successfully handled ...", domain) instances.set_success(domain) + logger.debug("rows[%s]()=%d", type(rows), len(rows)) if len(rows) == 0: logger.debug("domain='%s' has returned zero rows, trying /about/more page ...", domain) rows = fetch_blocks_from_about(domain) + logger.debug("rows[%s]()=%d", type(rows), len(rows)) if len(rows) > 0: logger.debug("Checking %d entries from domain='%s' ...", len(rows), domain) for block in rows: @@ -187,6 +190,10 @@ def fetch_blocks(domain: str, nodeinfo_url: str) -> list: if not isinstance(block, dict): logger.debug("block[]='%s' is of type 'dict' - SKIPPED!", type(block)) continue + elif "domain" not in block: + logger.warning("block()=%d does not contain element 'domain'", len(block)) + elif "severity" not in block: + logger.warning("block()=%d does not contain element 'severity'", len(block)) reason = tidyup.reason(block["comment"]) if "comment" in block and block["comment"] is not None and block["comment"] != "" else None