From: Roland Häder Date: Sat, 27 May 2023 08:07:00 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=bee6c9a4720a614408f64754e547ebe5c1697393;p=fba.git Continued: - ops, I need to check again API response code - also variable 'json' isn't here, need to take 'res.json()' directly --- diff --git a/fba.py b/fba.py index b5d536e..bc972f3 100644 --- a/fba.py +++ b/fba.py @@ -399,11 +399,14 @@ def get_peers(domain: str, software: str) -> list: if not res.ok or res.status_code >= 400: res = reqto.get(f"https://{domain}/api/v3/site", headers=headers, timeout=(config["connection_timeout"], config["read_timeout"])) - if "federated_instances" in json and "linked" in json["federated_instances"]: + if not res.ok or res.status_code >= 400: + print("WARNING: Could not reach any JSON API:", domain) + update_last_error(domain, res) + elif "federated_instances" in res.json() and "linked" in res.json()["federated_instances"]: # NOISY-DEBUG: print("DEBUG: Found federated_instances", domain) - peers = json["federated_instances"]["linked"] + json["federated_instances"]["allowed"] + json["federated_instances"]["blocked"] + peers = res.json()["federated_instances"]["linked"] + res.json()["federated_instances"]["allowed"] + res.json()["federated_instances"]["blocked"] else: - print("WARNING: Could not reach any JSON API:", domain) + print("WARNING: JSON response does not contain 'federated_instances':", domain) update_last_error(domain, res) else: # NOISY-DEBUG: print("DEBUG:Querying API was successful:", domain, len(res.json()))