]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Thu, 18 May 2023 01:23:59 +0000 (03:23 +0200)
committerRoland Häder <roland@mxchange.org>
Thu, 18 May 2023 01:23:59 +0000 (03:23 +0200)
- ops, to happy with "fba." adding
- added more debug lines

fetch_blocks.py

index 32449ecad1479d8e8beea96acb2020d11ce69e1b..b241fa18d38d076670acd2002ec7b7d07a602dbb 100644 (file)
@@ -118,18 +118,22 @@ for blocker, software in fba.c.fetchall():
                 }
 
                 # handling CSRF, I've saw at least one server requiring it to access the endpoint
+                print("DEBUG: Fetching meta:", blocker)
                 meta = bs4.BeautifulSoup(
                     reqto.get(f"https://{blocker}/about", headers=fba.headers, timeout=5).text,
                     "html.parser",
                 )
                 try:
                     csrf = meta.find("meta", attrs={"name": "csrf-token"})["content"]
-                    reqfba.headers = {**fba.headers, **{"x-csrf-token": csrf}}
+                    print("DEBUG: Adding CSRF token:", blocker, csrf)
+                    reqheaders = {**fba.headers, **{"x-csrf-token": csrf}}
                 except:
-                    reqfba.headers = fba.headers
+                    print("DEBUG: No CSRF token found, using normal headers:", blocker)
+                    reqheaders = fba.headers
 
+                print("DEBUG: Quering API domain_blocks:", blocker)
                 blocks = reqto.get(
-                    f"https://{blocker}/api/v1/instance/domain_blocks", headers=reqfba.headers, timeout=5
+                    f"https://{blocker}/api/v1/instance/domain_blocks", headers=reqheaders, timeout=5
                 ).json()
 
                 print("DEBUG: blocks():", len(blocks))
@@ -148,9 +152,12 @@ for blocker, software in fba.c.fetchall():
                     else:
                         print("WARNING: Unknown severity:", block['severity'], block['domain'])
             except:
+                print("DEBUG: Failed, Trying mastodon-specific fetches:", blocker)
                 json = fba.get_mastodon_blocks(blocker)
 
+            print("DEBUG: json.items():", blocker, len(json.items()))
             for block_level, blocks in json.items():
+                print("DEBUG: blocker,block_level,blocks():", blocker, block_level, len(blocks))
                 for instance in blocks:
                     blocked, blocked_hash, reason = instance.values()
                     print("DEBUG: blocked,hash,reason:", blocked, blocked_hash, reason)