From: Roland Häder Date: Sat, 20 May 2023 11:00:09 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=bed5614b668d12ae4fe3942ba626010b02c02d8e;p=fba.git Continued: - try block must be around software type checking, not the reqto.foo() call --- diff --git a/fba.py b/fba.py index 5d59ad4..53ef74c 100644 --- a/fba.py +++ b/fba.py @@ -110,26 +110,23 @@ def fetch_nodeinfo(domain: str) -> list: json = None for request in requests: - try: - # NOISY-DEBUG: print("DEBUG: Fetching request:", request) - res = reqto.get(request, headers=headers, timeout=5) - - # NOISY-DEBUG: print("DEBUG: res.ok,res.json[]:", res.ok, type(res.json())) - if res.ok and res.json() is not None: - # NOISY-DEBUG: print("DEBUG: Success:", request) - json = res.json() - break - elif not res.ok or res.status_code >= 400: - # NOISY-DEBUG: print("DEBUG: Failed fetching nodeinfo from domain:", domain) - update_last_error(domain, res) - continue - - except: - print("WARNING: Some error during get():", request) + # NOISY-DEBUG: print("DEBUG: Fetching request:", request) + res = reqto.get(request, headers=headers, timeout=5) + + # NOISY-DEBUG: print("DEBUG: res.ok,res.json[]:", res.ok, type(res.json())) + if res.ok and res.json() is not None: + # NOISY-DEBUG: print("DEBUG: Success:", request) + json = res.json() + break + elif not res.ok or res.status_code >= 400: + # NOISY-DEBUG: print("DEBUG: Failed fetching nodeinfo from domain:", domain) + update_last_error(domain, res) + continue if json is None: print("WARNING: Failed fetching nodeinfo from domain:", domain) + # NOISY-DEBUG: print("DEBUG: Updating last_nodeinfo for domain:", domain) update_last_nodeinfo(domain) # NOISY-DEBUG: print("DEBUG: Returning json():", len(json)) @@ -138,21 +135,26 @@ def fetch_nodeinfo(domain: str) -> list: def determine_software(domain: str) -> str: # NOISY-DEBUG: print("DEBUG: Determining software for domain:", domain) software = None - json = fetch_nodeinfo(domain) - # NOISY-DEBUG: print("DEBUG: json():", len(json)) - - if json["software"]["name"] in ["akkoma", "rebased"]: - # NOISY-DEBUG: print("DEBUG: Setting pleroma:", domain, json["software"]["name"]) - software = "pleroma" - elif json["software"]["name"] in ["hometown", "ecko"]: - # NOISY-DEBUG: print("DEBUG: Setting mastodon:", domain, json["software"]["name"]) - software = "mastodon" - elif json["software"]["name"] in ["calckey", "groundpolis", "foundkey", "cherrypick"]: - # NOISY-DEBUG: print("DEBUG: Setting misskey:", domain, json["software"]["name"]) - software = "misskey" - else: - # NOISY-DEBUG: print("DEBUG: Using name:", domain, json["software"]["name"]) - software = json["software"]["name"] + + try: + json = fetch_nodeinfo(domain) + # NOISY-DEBUG: print("DEBUG: json():", len(json)) + + if json["software"]["name"] in ["akkoma", "rebased"]: + # NOISY-DEBUG: print("DEBUG: Setting pleroma:", domain, json["software"]["name"]) + software = "pleroma" + elif json["software"]["name"] in ["hometown", "ecko"]: + # NOISY-DEBUG: print("DEBUG: Setting mastodon:", domain, json["software"]["name"]) + software = "mastodon" + elif json["software"]["name"] in ["calckey", "groundpolis", "foundkey", "cherrypick"]: + # NOISY-DEBUG: print("DEBUG: Setting misskey:", domain, json["software"]["name"]) + software = "misskey" + else: + # NOISY-DEBUG: print("DEBUG: Using name:", domain, json["software"]["name"]) + software = json["software"]["name"] + + except: + print("WARNING: Could not determine software type:", domain) # NOISY-DEBUG: print("DEBUG: Returning domain,software:", domain, software) return software