From 59cb36c384f6a4ffc9a4e94db9ebc04f642001a8 Mon Sep 17 00:00:00 2001 From: tazlin Date: Tue, 5 Mar 2024 21:02:46 -0500 Subject: [PATCH] fix: handle 401s for lora dls as terminal; spend less time retrying --- hordelib/model_manager/lora.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/hordelib/model_manager/lora.py b/hordelib/model_manager/lora.py index 736e1b50..4ea032e9 100644 --- a/hordelib/model_manager/lora.py +++ b/hordelib/model_manager/lora.py @@ -45,9 +45,9 @@ class LoraModelManager(BaseModelManager): LORA_API = "https://civitai.com/api/v1/models?types=LORA&sort=Highest%20Rated&primaryFileOnly=true" MAX_RETRIES = 10 if not TESTS_ONGOING else 3 MAX_DOWNLOAD_THREADS = 3 - RETRY_DELAY = 5 if not TESTS_ONGOING else 0.2 + RETRY_DELAY = 3 if not TESTS_ONGOING else 0.2 """The time to wait between retries in seconds""" - REQUEST_METADATA_TIMEOUT = 30 + REQUEST_METADATA_TIMEOUT = 20 """The time to wait for a response from the server in seconds""" REQUEST_DOWNLOAD_TIMEOUT = 300 """The time to wait for a response from the server in seconds""" @@ -528,14 +528,22 @@ def _download_thread(self, thread_number): except (requests.HTTPError, requests.ConnectionError, requests.Timeout, json.JSONDecodeError) as e: # We will retry logger.debug( - f"Error downloading {lora['versions'][version]['filename']} {e}. " + f"Error downloading {lora['versions'][version]['filename']} {e} ({type(e)}). " f"Retry {retries}/{self.MAX_RETRIES}", ) + # If this is a 401, we're not going to get anywhere, just just give up + if isinstance(e, requests.HTTPError) and e.response.status_code == 401: + logger.error( + f"Error downloading {lora['versions'][version]['filename']}. " + "CivitAI appears to be redirecting us to a login page. Aborting", + ) + break + except Exception as e: # Failed badly, ignore and retry logger.debug( - f"Fatal error downloading {lora['versions'][version]['filename']} {e}. " + f"Fatal error downloading {lora['versions'][version]['filename']} {e} ({type(e)}). " f"Retry {retries}/{self.MAX_RETRIES}", )