From 207f947a1c21a16b4aeac019dbbe2012d2c05dc0 Mon Sep 17 00:00:00 2001 From: AkashiCoin Date: Sun, 22 Sep 2024 17:12:21 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20fix(http=5Futils):=20=E6=B5=81=E5=BC=8F?= =?UTF-8?q?=E4=B8=8B=E8=BD=BDContent-Length=E9=94=99=E8=AF=AF=20(#1647)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __version__ | 2 +- zhenxun/utils/http_utils.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/__version__ b/__version__ index a9001b8f..069d8d5f 100644 --- a/__version__ +++ b/__version__ @@ -1 +1 @@ -__version__: v0.2.2-f9c7360 +__version__: v0.2.2-d539b1f diff --git a/zhenxun/utils/http_utils.py b/zhenxun/utils/http_utils.py index 1891e265..4637e108 100644 --- a/zhenxun/utils/http_utils.py +++ b/zhenxun/utils/http_utils.py @@ -286,7 +286,9 @@ class AsyncHttpx: f"Path: {path.absolute()}" ) async with aiofiles.open(path, "wb") as wf: - total = int(response.headers["Content-Length"]) + total = int( + response.headers.get("Content-Length", 0) + ) with rich.progress.Progress( # type: ignore rich.progress.TextColumn(path.name), # type: ignore "[progress.percentage]{task.percentage:>3.0f}%", # type: ignore @@ -295,7 +297,8 @@ class AsyncHttpx: rich.progress.TransferSpeedColumn(), # type: ignore ) as progress: download_task = progress.add_task( - "Download", total=total + "Download", + total=total if total else None, ) async for chunk in response.aiter_bytes(): await wf.write(chunk)