diff --git a/astrbot/core/utils/io.py b/astrbot/core/utils/io.py index 318a61835..7393cb424 100644 --- a/astrbot/core/utils/io.py +++ b/astrbot/core/utils/io.py @@ -8,6 +8,9 @@ import base64 import zipfile import uuid import psutil + +import certifi + from typing import Union from PIL import Image @@ -81,7 +84,13 @@ async def download_image_by_url( 下载图片, 返回 path """ try: - async with aiohttp.ClientSession(trust_env=True) as session: + ssl_context = ssl.create_default_context( + cafile=certifi.where() + ) # 使用 certifi 提供的 CA 证书 + connector = aiohttp.TCPConnector(ssl=ssl_context) # 使用 certifi 的根证书 + async with aiohttp.ClientSession( + trust_env=True, connector=connector + ) as session: if post: async with session.post(url, json=post_data) as resp: if not path: @@ -118,7 +127,13 @@ async def download_file(url: str, path: str, show_progress: bool = False): 从指定 url 下载文件到指定路径 path """ try: - async with aiohttp.ClientSession(trust_env=True) as session: + ssl_context = ssl.create_default_context( + cafile=certifi.where() + ) # 使用 certifi 提供的 CA 证书 + connector = aiohttp.TCPConnector(ssl=ssl_context) + async with aiohttp.ClientSession( + trust_env=True, connector=connector + ) as session: async with session.get(url, timeout=1800) as resp: if resp.status != 200: raise Exception(f"下载文件失败: {resp.status}") diff --git a/astrbot/core/utils/t2i/local_strategy.py b/astrbot/core/utils/t2i/local_strategy.py index 23abba6e6..aea3f4815 100644 --- a/astrbot/core/utils/t2i/local_strategy.py +++ b/astrbot/core/utils/t2i/local_strategy.py @@ -1,5 +1,7 @@ import re import aiohttp +import ssl +import certifi from io import BytesIO from . import RenderStrategy @@ -91,7 +93,9 @@ class LocalRenderStrategy(RenderStrategy): try: image_url = re.findall(IMAGE_REGEX, line)[0] print(image_url) - async with aiohttp.ClientSession(trust_env=True) as session: + ssl_context = ssl.create_default_context(cafile=certifi.where()) + connector = aiohttp.TCPConnector(ssl=ssl_context) + async with aiohttp.ClientSession(trust_env=True, connector=connector) as session: async with session.get(image_url) as resp: image_res = Image.open(BytesIO(await resp.read())) images[i] = image_res diff --git a/astrbot/core/utils/t2i/network_strategy.py b/astrbot/core/utils/t2i/network_strategy.py index b9b9abffe..f8f54b0dc 100644 --- a/astrbot/core/utils/t2i/network_strategy.py +++ b/astrbot/core/utils/t2i/network_strategy.py @@ -1,5 +1,7 @@ import aiohttp import os +import ssl +import certifi from . import RenderStrategy from astrbot.core.config import VERSION @@ -46,7 +48,11 @@ class NetworkRenderStrategy(RenderStrategy): }, } if return_url: - async with aiohttp.ClientSession(trust_env=True) as session: + ssl_context = ssl.create_default_context(cafile=certifi.where()) + connector = aiohttp.TCPConnector(ssl=ssl_context) + async with aiohttp.ClientSession( + trust_env=True, connector=connector + ) as session: async with session.post( f"{self.BASE_RENDER_URL}/generate", json=post_data ) as resp: diff --git a/astrbot/core/zip_updator.py b/astrbot/core/zip_updator.py index 29533ea88..4622b47cd 100644 --- a/astrbot/core/zip_updator.py +++ b/astrbot/core/zip_updator.py @@ -2,6 +2,10 @@ import aiohttp import os import zipfile import shutil + +import ssl +import certifi + from astrbot.core.utils.io import on_error, download_file from astrbot.core import logger @@ -33,10 +37,26 @@ class RepoZipUpdator: 返回一个列表,每个元素是一个字典,包含版本号、发布时间、更新内容、commit hash等信息。 """ try: - async with aiohttp.ClientSession(trust_env=True) as session: + ssl_context = ssl.create_default_context( + cafile=certifi.where() + ) # 新增:创建基于 certifi 的 SSL 上下文 + connector = aiohttp.TCPConnector( + ssl=ssl_context + ) # 新增:使用 TCPConnector 指定 SSL 上下文 + async with aiohttp.ClientSession( + trust_env=True, connector=connector + ) as session: async with session.get(url) as response: + # 检查 HTTP 状态码 + if response.status != 200: + text = await response.text() + logger.error( + f"请求 {url} 失败,状态码: {response.status}, 内容: {text}" + ) + raise Exception(f"请求失败,状态码: {response.status}") result = await response.json() if not result: + logger.error("返回空的结果") return [] # if latest: # ret = self.github_api_release_parser([result[0]]) @@ -53,7 +73,8 @@ class RepoZipUpdator: "zipball_url": release["zipball_url"], } ) - except BaseException: + except Exception as e: + logger.error(f"解析版本信息时发生异常: {e}") raise Exception("解析版本信息失败") return ret diff --git a/astrbot/dashboard/routes/plugin.py b/astrbot/dashboard/routes/plugin.py index 6e90d73e6..32dc99176 100644 --- a/astrbot/dashboard/routes/plugin.py +++ b/astrbot/dashboard/routes/plugin.py @@ -1,5 +1,9 @@ import traceback import aiohttp + +import ssl +import certifi + from .route import Route, Response, RouteContext from astrbot.core import logger from quart import request @@ -65,9 +69,14 @@ class PluginRoute(Route): else: urls = ["https://api.soulter.top/astrbot/plugins"] + # 新增:创建 SSL 上下文,使用 certifi 提供的根证书 + ssl_context = ssl.create_default_context(cafile=certifi.where()) + connector = aiohttp.TCPConnector(ssl=ssl_context) for url in urls: try: - async with aiohttp.ClientSession(trust_env=True) as session: + async with aiohttp.ClientSession( + trust_env=True, connector=connector + ) as session: async with session.get(url) as response: if response.status == 200: result = await response.json() diff --git a/astrbot/dashboard/routes/stat.py b/astrbot/dashboard/routes/stat.py index 5c197fad7..e73c09455 100644 --- a/astrbot/dashboard/routes/stat.py +++ b/astrbot/dashboard/routes/stat.py @@ -65,10 +65,7 @@ class StatRoute(Route): stat_dict = stat.__dict__ - # 获取系统CPU使用率而不是进程CPU使用率 cpu_percent = psutil.cpu_percent(interval=0.5) - - # 获取线程数 thread_count = threading.active_count() # 获取插件信息 diff --git a/dashboard/src/views/PlatformPage.vue b/dashboard/src/views/PlatformPage.vue index 38fa08e68..1af951306 100644 --- a/dashboard/src/views/PlatformPage.vue +++ b/dashboard/src/views/PlatformPage.vue @@ -96,7 +96,7 @@ - + {{ updatingMode ? 'mdi-pencil' : 'mdi-plus' }} @@ -105,12 +105,12 @@ - + - + mdi-refresh 刷新 diff --git a/requirements.txt b/requirements.txt index 313dba0c8..95983a2e8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -25,4 +25,5 @@ dashscope python-telegram-bot wechatpy dingtalk-stream -mcp \ No newline at end of file +mcp +certifi \ No newline at end of file