h
This commit is contained in:
44
API/HTTP.py
44
API/HTTP.py
@@ -95,9 +95,9 @@ def _resolve_verify_value(verify_ssl: bool) -> Union[bool, str]:
|
||||
if res:
|
||||
return res
|
||||
except Exception:
|
||||
pass
|
||||
logger.exception("Failed while probing certifi helper inner block")
|
||||
except Exception:
|
||||
pass
|
||||
logger.exception("Failed while invoking cert helper function")
|
||||
return None
|
||||
|
||||
# Prefer helpful modules if available (use safe checks to avoid first-chance import errors)
|
||||
@@ -107,7 +107,7 @@ def _resolve_verify_value(verify_ssl: bool) -> Union[bool, str]:
|
||||
try:
|
||||
os.environ["SSL_CERT_FILE"] = path
|
||||
except Exception:
|
||||
pass
|
||||
logger.exception("Failed to set SSL_CERT_FILE environment variable")
|
||||
logger.info(f"SSL_CERT_FILE not set; using bundle from {mod_name}: {path}")
|
||||
return path
|
||||
|
||||
@@ -120,11 +120,11 @@ def _resolve_verify_value(verify_ssl: bool) -> Union[bool, str]:
|
||||
try:
|
||||
os.environ["SSL_CERT_FILE"] = path
|
||||
except Exception:
|
||||
pass
|
||||
logger.exception("Failed to set SSL_CERT_FILE environment variable during certifi fallback")
|
||||
logger.info(f"SSL_CERT_FILE not set; using certifi bundle: {path}")
|
||||
return path
|
||||
except Exception:
|
||||
pass
|
||||
logger.exception("Failed to probe certifi for trust bundle")
|
||||
|
||||
# Fallback to certifi
|
||||
try:
|
||||
@@ -135,11 +135,11 @@ def _resolve_verify_value(verify_ssl: bool) -> Union[bool, str]:
|
||||
try:
|
||||
os.environ["SSL_CERT_FILE"] = path
|
||||
except Exception:
|
||||
pass
|
||||
logger.exception("Failed to set SSL_CERT_FILE environment variable during certifi fallback")
|
||||
logger.info(f"SSL_CERT_FILE not set; using certifi bundle: {path}")
|
||||
return path
|
||||
except Exception:
|
||||
pass
|
||||
logger.exception("Failed to probe certifi for trust bundle")
|
||||
|
||||
return True
|
||||
|
||||
@@ -400,7 +400,7 @@ class HTTPClient:
|
||||
try:
|
||||
progress_callback(0, total_bytes)
|
||||
except Exception:
|
||||
pass
|
||||
logger.exception("Error in progress_callback initial call")
|
||||
|
||||
with open(path, "wb") as f:
|
||||
for chunk in response.iter_bytes(chunk_size):
|
||||
@@ -415,7 +415,7 @@ class HTTPClient:
|
||||
try:
|
||||
progress_callback(bytes_downloaded, total_bytes)
|
||||
except Exception:
|
||||
pass
|
||||
logger.exception("Error in progress_callback final call")
|
||||
|
||||
return path
|
||||
|
||||
@@ -496,7 +496,7 @@ class HTTPClient:
|
||||
if 400 <= e.response.status_code < 500:
|
||||
try:
|
||||
response_text = e.response.text[:500]
|
||||
except:
|
||||
except Exception:
|
||||
response_text = "<unable to read response>"
|
||||
if log_http_errors:
|
||||
logger.error(
|
||||
@@ -506,7 +506,7 @@ class HTTPClient:
|
||||
last_exception = e
|
||||
try:
|
||||
response_text = e.response.text[:200]
|
||||
except:
|
||||
except Exception:
|
||||
response_text = "<unable to read response>"
|
||||
logger.warning(
|
||||
f"HTTP {e.response.status_code} on attempt {attempt + 1}/{self.retries}: {url} - {response_text}"
|
||||
@@ -715,7 +715,7 @@ def download_direct_file(
|
||||
except DownloadError:
|
||||
raise
|
||||
except Exception:
|
||||
pass
|
||||
logger.exception("Unexpected error while probing URL content")
|
||||
|
||||
suggested = _sanitize_filename(suggested_filename) if suggested_filename else ""
|
||||
if suggested:
|
||||
@@ -727,12 +727,14 @@ def download_direct_file(
|
||||
try:
|
||||
detected_ext = Path(str(filename)).suffix
|
||||
except Exception:
|
||||
logger.exception("Failed to detect file extension from filename")
|
||||
detected_ext = ""
|
||||
filename = suggested + detected_ext if detected_ext else suggested
|
||||
|
||||
try:
|
||||
has_ext = bool(filename and Path(str(filename)).suffix)
|
||||
except Exception:
|
||||
logger.exception("Failed to determine if filename has extension")
|
||||
has_ext = False
|
||||
|
||||
if filename and (not has_ext):
|
||||
@@ -823,7 +825,7 @@ def download_direct_file(
|
||||
total=total_val,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
logger.exception("Error updating pipeline progress transfer")
|
||||
|
||||
if progress_bar is not None:
|
||||
progress_bar.update(
|
||||
@@ -842,7 +844,7 @@ def download_direct_file(
|
||||
if progress_bar is not None:
|
||||
progress_bar.finish()
|
||||
except Exception:
|
||||
pass
|
||||
logger.exception("Failed to finish progress bar")
|
||||
|
||||
try:
|
||||
if pipeline_progress is not None and transfer_started[0] and hasattr(
|
||||
@@ -850,7 +852,7 @@ def download_direct_file(
|
||||
):
|
||||
pipeline_progress.finish_transfer(label=str(filename or "download"))
|
||||
except Exception:
|
||||
pass
|
||||
logger.exception("Failed to finish pipeline transfer")
|
||||
|
||||
if not quiet:
|
||||
debug(f"✓ Downloaded in {elapsed:.1f}s")
|
||||
@@ -871,7 +873,7 @@ def download_direct_file(
|
||||
try:
|
||||
hash_value = sha256_file(file_path)
|
||||
except Exception:
|
||||
pass
|
||||
logger.exception("Failed to compute SHA256 of downloaded file")
|
||||
|
||||
tags: List[str] = []
|
||||
if extract_ytdlp_tags is not None:
|
||||
@@ -908,14 +910,14 @@ def download_direct_file(
|
||||
if progress_bar is not None:
|
||||
progress_bar.finish()
|
||||
except Exception:
|
||||
pass
|
||||
logger.exception("Failed to finish progress bar during HTTP error handling")
|
||||
try:
|
||||
if pipeline_progress is not None and transfer_started[0] and hasattr(
|
||||
pipeline_progress, "finish_transfer"
|
||||
):
|
||||
pipeline_progress.finish_transfer(label=str(filename or "download"))
|
||||
except Exception:
|
||||
pass
|
||||
logger.exception("Failed to finish pipeline transfer during HTTP error handling")
|
||||
|
||||
log(f"Download error: {exc}", file=sys.stderr)
|
||||
if debug_logger is not None:
|
||||
@@ -930,14 +932,14 @@ def download_direct_file(
|
||||
if progress_bar is not None:
|
||||
progress_bar.finish()
|
||||
except Exception:
|
||||
pass
|
||||
logger.exception("Failed to finish progress bar during error handling")
|
||||
try:
|
||||
if pipeline_progress is not None and transfer_started[0] and hasattr(
|
||||
pipeline_progress, "finish_transfer"
|
||||
):
|
||||
pipeline_progress.finish_transfer(label=str(filename or "download"))
|
||||
except Exception:
|
||||
pass
|
||||
logger.exception("Failed to finish pipeline transfer during error handling")
|
||||
|
||||
log(f"Error downloading file: {exc}", file=sys.stderr)
|
||||
if debug_logger is not None:
|
||||
@@ -1163,7 +1165,7 @@ class AsyncHTTPClient:
|
||||
last_exception = e
|
||||
try:
|
||||
response_text = e.response.text[:200]
|
||||
except:
|
||||
except Exception:
|
||||
response_text = "<unable to read response>"
|
||||
logger.warning(
|
||||
f"HTTP {e.response.status_code} on attempt {attempt + 1}/{self.retries}: {url} - {response_text}"
|
||||
|
||||
Reference in New Issue
Block a user