try:
logger.debug("Sending GET to domain='%s',path='%s',timeout(%d)='%s'", domain, path, len(timeout), timeout)
- response = reqto.get(
- f"https://{domain}{path}",
- headers={**api_headers, **headers},
- timeout=timeout,
- cookies=cookies.get_all(domain),
- allow_redirects=False
- )
-
+ response = fetch_response(domain, path, headers, timeout)
except exceptions as exception:
logger.debug("Fetching path='%s' from domain='%s' failed. exception[%s]='%s'", path, domain, type(exception), str(exception))
json_reply["status_code"] = 999
for block in blocklist:
logger.debug("block[%s]='%s'", type(block), block)
if block["reason"] is None or block["reason"] == '':
+ logger.debug("block[blocked]='%s' is being blocked with no reason specified", block["blocked"])
message = message + block["blocked"] + " with unspecified reason\n"
else:
+ logger.debug("block[reason]()=%d", len(block["reason"]))
if len(block["reason"]) > 420:
block["reason"] = block["reason"][0:419] + "[…]"
if truncated:
message = message + "(the list has been truncated to the first 20 entries)"
- botheaders = {**api_headers, **{"Authorization": "Bearer " + config.get("bot_token")}}
-
- req = reqto.post(
+ response = reqto.post(
f"{config.get('bot_instance')}/api/v1/statuses",
data={
"status" : message,
- "visibility" : config.get('bot_visibility'),
+ "visibility" : config.get("bot_visibility"),
"content_type": "text/plain"
},
- headers=botheaders,
+ headers={**api_headers, **{"Authorization": "Bearer " + config.get("bot_token")}},
timeout=(config.get("connection_timeout"), config.get("read_timeout")),
allow_redirects=False
- ).json()
+ )
- return True
+ logger.debug("response.ok='%s',response.status_code=%d,response.text()=%d", response.ok, response.status_code, len(response.text))
+ return response.ok and response.status_code < 300 and response.text.strip() != ""
def fetch_response(domain: str, path: str, headers: dict, timeout: tuple, allow_redirects: bool = False) -> requests.models.Response:
logger.debug("domain='%s',path='%s',headers()=%d,timeout='%s',allow_redirects='%s' - CALLED!", domain, path, len(headers), timeout, allow_redirects)