better fix for 525

This commit is contained in:
bobokun 2021-12-20 10:28:29 -05:00
parent 1decfdcd7f
commit 0877bf327b
No known key found for this signature in database
GPG key ID: 9665BA6CF5DC2671
3 changed files with 36 additions and 34 deletions

View file

@ -110,10 +110,7 @@ class Config:
}) })
except Failed as e: except Failed as e:
logger.error(e) logger.error(e)
notifiarr_error = str(e) logger.info(f"Notifiarr Connection {'Failed' if self.NotifiarrFactory is None else 'Successful'}")
if '525' in notifiarr_error:
self.NotifiarrFactory = notifiarr_error
logger.info(f"Notifiarr Connection {'Failed' if self.NotifiarrFactory is (None or notifiarr_error) else 'Successful'}")
else: else:
logger.warning("Config Warning: notifiarr attribute not found") logger.warning("Config Warning: notifiarr attribute not found")

View file

@ -20,12 +20,12 @@ class Notifiarr:
response = self.config.get(url) response = self.config.get(url)
try: try:
response_json = response.json() response_json = response.json()
except JSONDecodeError: except JSONDecodeError as e:
if response.status_code >= 400: if response.status_code >= 400:
if response.status_code == 525: if response.status_code == 525:
raise Failed(f"Notifiarr Error (Response: 525): SSL handshake between Cloudflare and the origin web server failed.") raise Failed(f"Notifiarr Error (Response: 525): SSL handshake between Cloudflare and the origin web server failed.")
else: else:
raise Failed(f"({response.status_code} [{response.reason}])") raise Failed(e)
if response.status_code >= 400 or ("result" in response_json and response_json["result"] == "error"): if response.status_code >= 400 or ("result" in response_json and response_json["result"] == "error"):
logger.debug(f"Response: {response_json}") logger.debug(f"Response: {response_json}")
raise Failed(f"({response.status_code} [{response.reason}]) {response_json}") raise Failed(f"({response.status_code} [{response.reason}]) {response_json}")

View file

@ -26,42 +26,47 @@ class Webhooks:
logger.debug("") logger.debug("")
logger.debug(f"JSON: {json}") logger.debug(f"JSON: {json}")
for webhook in list(set(webhooks)): for webhook in list(set(webhooks)):
response = None
if self.config.trace_mode: if self.config.trace_mode:
logger.debug(f"Webhook: {webhook}") logger.debug(f"Webhook: {webhook}")
if webhook == "notifiarr": if webhook == "notifiarr":
if self.notifiarr is None: if self.notifiarr is None:
raise Failed(f"Webhook attribute set to notifiarr but notifiarr attribute is not configured.") break
elif '525' in self.notifiarr: else:
raise Failed(self.notifiarr) url, params = self.notifiarr.get_url("notification/qbitManage/")
url, params = self.notifiarr.get_url("notification/qbitManage/") for x in range(6):
for x in range(6): response = self.config.get(url, json=json, params=params)
response = self.config.get(url, json=json, params=params) if response.status_code < 500:
if response.status_code < 500: break
break
elif webhook == "apprise": elif webhook == "apprise":
if self.apprise is None: if self.apprise is None:
raise Failed(f"Webhook attribute set to apprise but apprise attribute is not configured.") logger.warning(f"Webhook attribute set to apprise but apprise attribute is not configured.")
json['urls'] = self.apprise.notify_url break
response = self.config.post(f"{self.apprise.api_url}/notify", json=json) else:
json['urls'] = self.apprise.notify_url
for x in range(6):
response = self.config.post(f"{self.apprise.api_url}/notify", json=json)
if response.status_code < 500:
break
else: else:
response = self.config.post(webhook, json=json) response = self.config.post(webhook, json=json)
if response:
skip = False skip = False
try: try:
response_json = response.json() response_json = response.json()
if self.config.trace_mode: if self.config.trace_mode:
logger.debug(f"Response: {response_json}") logger.debug(f"Response: {response_json}")
if "result" in response_json and response_json["result"] == "error" and "details" in response_json and "response" in response_json["details"]: if "result" in response_json and response_json["result"] == "error" and "details" in response_json and "response" in response_json["details"]:
if ('trigger is not enabled' in response_json['details']['response']): if ('trigger is not enabled' in response_json['details']['response']):
logger.debug(f"Notifiarr Warning: {response_json['details']['response']}") logger.debug(f"Notifiarr Warning: {response_json['details']['response']}")
skip = True skip = True
else: else:
raise Failed(f"Notifiarr Error: {response_json['details']['response']}") raise Failed(f"Notifiarr Error: {response_json['details']['response']}")
if (response.status_code >= 400 or ("result" in response_json and response_json["result"] == "error")) and skip == False: if (response.status_code >= 400 or ("result" in response_json and response_json["result"] == "error")) and skip == False:
raise Failed(f"({response.status_code} [{response.reason}]) {response_json}") raise Failed(f"({response.status_code} [{response.reason}]) {response_json}")
except JSONDecodeError: except JSONDecodeError:
if response.status_code >= 400: if response.status_code >= 400:
raise Failed(f"({response.status_code} [{response.reason}])") raise Failed(f"({response.status_code} [{response.reason}])")
def start_time_hooks(self, start_time): def start_time_hooks(self, start_time):
if self.run_start_webhooks: if self.run_start_webhooks: