diff --git a/API/HydrusNetwork.py b/API/HydrusNetwork.py index 4a139b8..f184214 100644 --- a/API/HydrusNetwork.py +++ b/API/HydrusNetwork.py @@ -143,7 +143,8 @@ class HydrusNetwork: try: with HTTPClient(timeout=self.timeout, headers=headers, - verify_ssl=False) as client: + verify_ssl=False, + retries=1) as client: response = None if spec.file_path is not None: @@ -206,14 +207,30 @@ class HydrusNetwork: finally: _render_progress(final=True) - response = client.request( - spec.method, - url, - content=file_gen(), - headers=headers, - raise_for_status=False, - log_http_errors=False, - ) + upload_attempts = 3 + last_upload_exc: Exception | None = None + for attempt in range(upload_attempts): + try: + response = client.request( + spec.method, + url, + content=file_gen(), + headers=headers, + raise_for_status=False, + log_http_errors=False, + ) + last_upload_exc = None + break + except (httpx.TimeoutException, httpx.RequestError) as exc: + last_upload_exc = exc + logger.warning( + f"{self._log_prefix()} Upload timeout/error on attempt {attempt + 1}/{upload_attempts}: {exc}" + ) + if attempt < upload_attempts - 1: + continue + raise + if response is None and last_upload_exc is not None: + raise last_upload_exc else: content = None json_data = None diff --git a/Store/HydrusNetwork.py b/Store/HydrusNetwork.py index 56d7b0b..35e9625 100644 --- a/Store/HydrusNetwork.py +++ b/Store/HydrusNetwork.py @@ -397,6 +397,24 @@ class HydrusNetwork(Store): if isinstance(hashes, list) and hashes: hydrus_hash = hashes[0] + if isinstance(hydrus_hash, (bytes, bytearray)): + try: + hydrus_hash = bytes(hydrus_hash).hex() + except Exception: + hydrus_hash = None + + if hydrus_hash: + try: + hydrus_hash = str(hydrus_hash).strip().lower() + except Exception: + hydrus_hash = None + + if not hydrus_hash or len(str(hydrus_hash)) != 64: + debug( + f"{self._log_prefix()} Hydrus response hash missing/invalid; using precomputed hash" + ) + hydrus_hash = file_hash + if not hydrus_hash: raise Exception(f"Hydrus response missing file hash: {response}")