From 9138446bb8e3eeb2ad99ff40c755343103dfc7a1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 4 Jun 2023 15:37:05 +0200 Subject: [PATCH] Continued: - package/module of JSONDecodeError is json.decoder.JSONDecodeError --- fba/fba.py | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/fba/fba.py b/fba/fba.py index 1bab14f..623e5e0 100644 --- a/fba/fba.py +++ b/fba/fba.py @@ -380,7 +380,7 @@ def log_error(domain: str, res: any): try: # DEBUG: print("DEBUG: BEFORE res[]:", type(res)) - if isinstance(res, BaseException) or isinstance(res, json.JSONDecodeError): + if isinstance(res, BaseException) or isinstance(res, json.decoder.JSONDecodeError): res = str(res) # DEBUG: print("DEBUG: AFTER res[]:", type(res)) @@ -415,7 +415,7 @@ def update_last_error(domain: str, res: any): raise ValueError(f"Parameter 'domain' cannot be empty") # DEBUG: print("DEBUG: BEFORE res[]:", type(res)) - if isinstance(res, BaseException) or isinstance(res, json.JSONDecodeError): + if isinstance(res, BaseException) or isinstance(res, json.decoder.JSONDecodeError): res = f"{type}:str(res)" # DEBUG: print("DEBUG: AFTER res[]:", type(res)) @@ -495,14 +495,18 @@ def get_peers(domain: str, software: str) -> list: "sort" : "+pubAt", "host" : None, "limit": step - }), {"Origin": domain}) + }), { + "Origin": domain + }) else: fetched = post_json_api(domain, "/api/federation/instances", json.dumps({ "sort" : "+pubAt", "host" : None, "limit" : step, "offset": offset - 1 - }), {"Origin": domain}) + }), { + "Origin": domain + }) # DEBUG: print(f"DEBUG: fetched()={len(fetched))}") if len(fetched) == 0: @@ -1327,7 +1331,9 @@ def get_misskey_blocks(domain: str) -> dict: "host" : None, "suspended": True, "limit" : step - }), {"Origin": domain}) + }), { + "Origin": domain + }) else: # DEBUG: print("DEBUG: Sending JSON API request to domain,step,offset:", domain, step, offset) fetched = post_json_api(domain, "/api/federation/instances", json.dumps({ @@ -1336,7 +1342,9 @@ def get_misskey_blocks(domain: str) -> dict: "suspended": True, "limit" : step, "offset" : offset - 1 - }), {"Origin": domain}) + }), { + "Origin": domain + }) # DEBUG: print("DEBUG: fetched():", len(fetched)) if len(fetched) == 0: @@ -1376,7 +1384,9 @@ def get_misskey_blocks(domain: str) -> dict: "host" : None, "blocked": True, "limit" : step - }), {"Origin": domain}) + }), { + "Origin": domain + }) else: # DEBUG: print("DEBUG: Sending JSON API request to domain,step,offset:", domain, step, offset) fetched = post_json_api(domain,"/api/federation/instances", json.dumps({ @@ -1384,8 +1394,10 @@ def get_misskey_blocks(domain: str) -> dict: "host" : None, "blocked": True, "limit" : step, - "offset" : offset-1 - }), {"Origin": domain}) + "offset" : offset - 1 + }), { + "Origin": domain + }) # DEBUG: print("DEBUG: fetched():", len(fetched)) if len(fetched) == 0: @@ -1456,7 +1468,7 @@ def json_from_response(response: requests.models.Response) -> list: # DEBUG: print(f"DEBUG: response.text()={len(response.text)} is not empty, invoking response.json() ...") try: data = response.json() - except json.JSONDecodeError: + except json.decoder.JSONDecodeError: pass # DEBUG: print(f"DEBUG: data[]={type(data)} - EXIT!") -- 2.39.5