]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sun, 21 May 2023 16:03:23 +0000 (18:03 +0200)
committerRoland Häder <roland@mxchange.org>
Sun, 21 May 2023 16:03:23 +0000 (18:03 +0200)
- keep connection and read timeout separate

config.defaults.json
fba.py
fetch_blocks.py

index d2a1a42f838da41766c7b62a310744632ccb7a61..397365d83adb9ce3ee9c239c66c19ff9c2d1cd96 100644 (file)
@@ -1,14 +1,15 @@
 {
-    "base_url"        : "",
-    "log_level"       : "info",
-    "port"            : 8069,
-    "useragent"       : "Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101 Firefox/102.0",
-    "timeout"         : 5,
-    "bot_enabled"     : false,
-    "bot_instance"    : "https://example.com",
-    "bot_token"       : "",
-    "bot_visibility"  : "unlisted",
-    "slogan"          : "### Your footer slogan ###",
-    "recheck_instance": 3600,
-    "recheck_block"   : 3600
+    "base_url"          : "",
+    "log_level"         : "info",
+    "port"              : 8069,
+    "useragent"         : "Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101 Firefox/102.0",
+    "connection_timeout": 2,
+    "read_timeout"      : 5,
+    "bot_enabled"       : false,
+    "bot_instance"      : "https://example.com",
+    "bot_token"         : "",
+    "bot_visibility"    : "unlisted",
+    "slogan"            : "### Your footer slogan ###",
+    "recheck_instance"  : 3600,
+    "recheck_block"     : 3600
 }
diff --git a/fba.py b/fba.py
index 4505d44af4bc70614035287d43b3bf2b987de1c7..6c86916a6ee92ad1e3e6ffcf8af26be8ebb0a925 100644 (file)
--- a/fba.py
+++ b/fba.py
@@ -90,7 +90,7 @@ def get_peers(domain: str) -> list:
     peers = None
 
     try:
-        res = reqto.get(f"https://{domain}/api/v1/instance/peers", headers=headers, timeout=config["timeout"])
+        res = reqto.get(f"https://{domain}/api/v1/instance/peers", headers=headers, timeout=(config["connection_timeout"], config["read_timeout"]))
 
         if not res.ok or res.status_code >= 400:
             print("WARNING: Cannot fetch peers:", domain)
@@ -110,7 +110,7 @@ def get_peers(domain: str) -> list:
 def post_json_api(domain: str, path: str, data: str) -> list:
     # NOISY-DEBUG: print("DEBUG: Sending POST to domain,path,data:", domain, path, data)
     try:
-        res = reqto.post(f"https://{domain}{path}", data=data, headers=headers, timeout=config["timeout"])
+        res = reqto.post(f"https://{domain}{path}", data=data, headers=headers, timeout=(config["connection_timeout"], config["read_timeout"]))
 
         if not res.ok or res.status_code >= 400:
             print("WARNING: Cannot query JSON API:", domain, path, data, res.status_code)
@@ -139,7 +139,7 @@ def fetch_nodeinfo(domain: str) -> list:
     json = None
     for request in requests:
         # NOISY-DEBUG: print("DEBUG: Fetching request:", request)
-        res = reqto.get(request, headers=headers, timeout=config["timeout"])
+        res = reqto.get(request, headers=headers, timeout=(config["connection_timeout"], config["read_timeout"]))
 
         # NOISY-DEBUG: print("DEBUG: res.ok,res.json[]:", res.ok, type(res.json()))
         if res.ok and res.json() is not None:
@@ -332,7 +332,7 @@ def get_mastodon_blocks(domain: str) -> dict:
 
     try:
         doc = BeautifulSoup(
-            reqto.get(f"https://{domain}/about/more", headers=headers, timeout=config["timeout"]).text,
+            reqto.get(f"https://{domain}/about/more", headers=headers, timeout=(config["connection_timeout"], config["read_timeout"])).text,
             "html.parser",
         )
     except:
@@ -369,7 +369,7 @@ def get_friendica_blocks(domain: str) -> dict:
 
     try:
         doc = BeautifulSoup(
-            reqto.get(f"https://{domain}/friendica", headers=headers, timeout=config["timeout"]).text,
+            reqto.get(f"https://{domain}/friendica", headers=headers, timeout=(config["connection_timeout"], config["read_timeout"])).text,
             "html.parser",
         )
     except:
index 6363971425404fadaa2b7029983d763a05630c84..7f5d857ec1bc00a371a2d1a20c5c3977f03921e2 100644 (file)
@@ -165,7 +165,7 @@ for blocker, software in fba.cursor.fetchall():
                 # handling CSRF, I've saw at least one server requiring it to access the endpoint
                 # NOISY-DEBUG: print("DEBUG: Fetching meta:", blocker)
                 meta = bs4.BeautifulSoup(
-                    reqto.get(f"https://{blocker}/about", headers=fba.headers, timeout=fba.config["timeout"]).text,
+                    reqto.get(f"https://{blocker}/about", headers=fba.headers, timeout=fba.(config["connection_timeout"], config["read_timeout"])).text,
                     "html.parser",
                 )
                 try:
@@ -177,7 +177,7 @@ for blocker, software in fba.cursor.fetchall():
                     reqheaders = fba.headers
 
                 # NOISY-DEBUG: print("DEBUG: Quering API domain_blocks:", blocker)
-                blocks = reqto.get(f"https://{blocker}/api/v1/instance/domain_blocks", headers=reqheaders, timeout=fba.config["timeout"]).json()
+                blocks = reqto.get(f"https://{blocker}/api/v1/instance/domain_blocks", headers=reqheaders, timeout=fba.(config["connection_timeout"], config["read_timeout"])).json()
 
                 # NOISY-DEBUG: print("DEBUG: blocks():", len(blocks))
                 for block in blocks:
@@ -347,7 +347,7 @@ for blocker, software in fba.cursor.fetchall():
         print("INFO: blocker:", blocker)
         try:
             # Blocks
-            federation = reqto.get(f"https://{blocker}/api/v1/instance/peers?filter=suspended", headers=fba.headers, timeout=fba.config["timeout"]).json()
+            federation = reqto.get(f"https://{blocker}/api/v1/instance/peers?filter=suspended", headers=fba.headers, timeout=fba.(config["connection_timeout"], config["read_timeout"])).json()
 
             if (federation == None):
                 print("WARNING: No valid response:", blocker);