From 218e887558ca6fea696fad652b62d9c3665e62a2 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Sun, 12 Jan 2025 11:41:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20download=5Ffile=20=E4=BF=AE=E5=A4=8D=20S?= =?UTF-8?q?SL=20=E8=BF=9E=E6=8E=A5=E9=94=99=E8=AF=AF=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/utils/io.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/astrbot/core/utils/io.py b/astrbot/core/utils/io.py index a20b3f27a..a268ad522 100644 --- a/astrbot/core/utils/io.py +++ b/astrbot/core/utils/io.py @@ -87,7 +87,7 @@ async def download_image_by_url(url: str, post: bool = False, post_data: dict = with open(path, "wb") as f: f.write(await resp.read()) return path - except aiohttp.client_exceptions.ClientConnectorSSLError: + except aiohttp.client.ClientConnectorSSLError: # 关闭SSL验证 ssl_context = ssl.create_default_context() ssl_context.set_ciphers('DEFAULT') @@ -116,8 +116,18 @@ async def download_file(url: str, path: str): if not chunk: break f.write(chunk) - except Exception as e: - raise e + except aiohttp.client.ClientConnectorSSLError: + # 关闭SSL验证 + ssl_context = ssl.create_default_context() + ssl_context.set_ciphers('DEFAULT') + async with aiohttp.ClientSession(trust_env=False) as session: + async with session.get(url, ssl=ssl_context, timeout=20) as resp: + with open(path, 'wb') as f: + while True: + chunk = await resp.content.read(8192) + if not chunk: + break + f.write(chunk) def file_to_base64(file_path: str) -> str: with open(file_path, "rb") as f: