From: Roland Häder Date: Sun, 18 Jun 2023 09:55:42 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=2e4b12cd8816ba3f14c726d760255852acc6a222;p=fba.git Continued: - some link[href] results from nodeinfo may not have complete URLs - strange, but true. they need to be prepended with https://{domain} --- diff --git a/fba/federation.py b/fba/federation.py index 9ccbc60..97dc786 100644 --- a/fba/federation.py +++ b/fba/federation.py @@ -252,7 +252,7 @@ def fetch_nodeinfo(domain: str, path: str = None) -> dict: if path is None or path == request or path == f"http://{domain}{path}" or path == f"https://{domain}{path}": # DEBUG: print(f"DEBUG: Fetching request='{request}' from domain='{domain}' ...") if path == f"http://{domain}{path}" or path == f"https://{domain}{path}": - print(f"DEBUG: domain='{domain}',path='{path}' has protocol in path, splitting ...") + # DEBUG: print(f"DEBUG: domain='{domain}',path='{path}' has protocol in path, splitting ...") components = urlparse(path) path = components.path @@ -315,9 +315,18 @@ def fetch_wellknown_nodeinfo(domain: str) -> dict: if not isinstance(link, dict) or not "rel" in link: print(f"WARNING: link[]='{type(link)}' is not 'dict' or no element 'rel' found") elif link["rel"] in nodeinfo_identifier: - # DEBUG: print("DEBUG: Fetching nodeinfo from:", link["href"]) + # Default is that 'href' has a complete URL, but some hosts don't send that + url = link["href"] + components = urlparse(link["href"]) + + # DEBUG: print(f"DEBUG: components[{type(components)}]='{components}'") + if components.scheme == "" and components.netloc == "": + # DEBUG: print(f"DEBUG: link[href]='{link['href']}' has no scheme and host name in it, prepending from domain='{domain}'") + url = f"https://{domain}{url}" + + # DEBUG: print("DEBUG: Fetching nodeinfo from:", url) data = network.fetch_api_url( - link["href"], + url, (config.get("connection_timeout"), config.get("read_timeout")) ) @@ -365,7 +374,7 @@ def fetch_generator_from_path(domain: str, path: str = "/") -> str: # DEBUG: print(f"DEBUG: generator='{generator}',site_name='{site_name}'") if isinstance(generator, bs4.element.Tag) and isinstance(generator.get("content"), str): - print("DEBUG: Found generator meta tag:", domain) + # DEBUG: print("DEBUG: Found generator meta tag:", domain) software = tidyup.domain(generator.get("content")) # DEBUG: print(f"DEBUG: software[{type(software)}]='{software}'") if software is not None and software != "": diff --git a/fba/networks/mastodon.py b/fba/networks/mastodon.py index 7d836ed..293b8dd 100644 --- a/fba/networks/mastodon.py +++ b/fba/networks/mastodon.py @@ -232,7 +232,7 @@ def fetch_blocks(domain: str, origin: str, nodeinfo_url: str): print("WARNING: block_level is empty, domain:", domain) continue elif block_level == "accept": - print(f"DEBUG: domain='{domain}' skipping block_level='accept'") + # DEBUG: print(f"DEBUG: domain='{domain}' skipping block_level='accept'") continue # DEBUG: print(f"DEBUG: Checking {len(blocklist)} entries from domain='{domain}',software='mastodon',block_level='{block_level}' ...") diff --git a/fba/networks/pleroma.py b/fba/networks/pleroma.py index f017df3..39ca927 100644 --- a/fba/networks/pleroma.py +++ b/fba/networks/pleroma.py @@ -93,7 +93,7 @@ def fetch_blocks(domain: str, origin: str, nodeinfo_url: str): print("WARNING: block_level is now empty!") continue elif block_level == "accept": - print(f"DEBUG: domain='{domain}' skipping block_level='accept'") + # DEBUG: print(f"DEBUG: domain='{domain}' skipping block_level='accept'") continue # DEBUG: print(f"DEBUG: Checking {len(blocklist)} entries from domain='{domain}',block_level='{block_level}' ...") @@ -257,7 +257,7 @@ def fetch_blocks(domain: str, origin: str, nodeinfo_url: str): print("WARNING: block_level is now empty!") continue elif block_level == "accept": - print(f"DEBUG: domain='{domain}' skipping block_level='accept'") + # DEBUG: print(f"DEBUG: domain='{domain}' skipping block_level='accept'") continue # DEBUG: print(f"DEBUG: Checking {len(info.items())} entries from domain='{domain}',software='pleroma',block_level='{block_level}' ...")