fix: handle bot blocking siteinfo

pull/54/head
db0 2023-10-15 14:31:06 +02:00
parent b165711c4b
commit 4ab98ec12b
2 changed files with 25 additions and 5 deletions

View File

@ -176,7 +176,12 @@ class InstanceInfo():
def get_mastodon_info(self):
site = requests.get(f"https://{self.domain}/api/v1/instance",timeout=self._req_timeout)
self.instance_info = site.json()
try:
self.instance_info = site.json()
except Exception as err:
if "challenge-error-text" in site.text:
raise Exception("Instance is preventing scripted retrieval of their site info.")
raise err
self.approval_required = self.instance_info["approval_required"]
if self.node_info is None:
raise Exception("Error retrieving nodeinfo")
@ -186,7 +191,12 @@ class InstanceInfo():
def get_pleroma_info(self):
site = requests.get(f"https://{self.domain}/api/v1/instance",timeout=self._req_timeout)
self.instance_info = site.json()
try:
self.instance_info = site.json()
except Exception as err:
if "challenge-error-text" in site.text:
raise Exception("Instance is preventing scripted retrieval of their site info.")
raise err
self.approval_required = self.instance_info["approval_required"]
if self.node_info is None:
raise Exception("Error retrieving nodeinfo")
@ -196,7 +206,12 @@ class InstanceInfo():
def get_firefish_info(self):
site = requests.get(f"https://{self.domain}/api/v1/instance",timeout=self._req_timeout)
self.instance_info = site.json()
try:
self.instance_info = site.json()
except Exception as err:
if "challenge-error-text" in site.text:
raise Exception("Instance is preventing scripted retrieval of their site info.")
raise err
self.approval_required = self.instance_info["approval_required"]
if self.node_info is None:
raise Exception("Error retrieving nodeinfo")
@ -213,7 +228,12 @@ class InstanceInfo():
site = requests.get(f"https://{self.domain}/api/v1/instance",timeout=self._req_timeout,allow_redirects=False)
if site.status_code != 200:
raise Exception(f"Unexpected status code retrieved when discovering instance info: {site.status_code}")
self.instance_info = site.json()
try:
self.instance_info = site.json()
except Exception as err:
if "challenge-error-text" in site.text:
raise Exception("Instance is preventing scripted retrieval of their site info.")
raise err
self.approval_required = self.instance_info.get("approval_required")
if self.node_info is None:
raise Exception("Error retrieving nodeinfo")

View File

@ -26,7 +26,7 @@ def ensure_instance_registered(domain, allow_unreachable=False, record_unreachab
instance.poll_failures += 60
db.session.commit()
if not allow_unreachable:
raise e.BadRequest(f"Error encountered while polling domain {domain}. Please check it's running correctly")
raise e.BadRequest(str(err))
if instance:
if (
instance.software != instance_info.software or