]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sat, 27 May 2023 08:07:00 +0000 (10:07 +0200)
committerRoland Häder <roland@mxchange.org>
Sat, 27 May 2023 08:07:00 +0000 (10:07 +0200)
- ops, I need to check again API response code
- also variable 'json' isn't here, need to take 'res.json()' directly

fba.py

diff --git a/fba.py b/fba.py
index b5d536e8bf7d9a2b02517eb6ebbabc4440e75e0f..bc972f32f24c84470835d5319cc04e18b392a9c7 100644 (file)
--- 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()))