From d3381b7872268a3fbc3493428b2f962f47a941a2 Mon Sep 17 00:00:00 2001 From: youkang <1062424570@qq.com> Date: Sun, 4 May 2025 16:12:01 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=B1=E4=BA=8E=E8=B0=83=E7=94=A8=E5=8A=A0?= =?UTF-8?q?=E9=80=9F=E5=9C=B0=E5=9D=80=E7=9A=84=E6=97=B6=E5=80=99=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E7=A0=81=E4=B8=BA302=E4=BC=9A=E8=A2=AB=E8=AE=A4?= =?UTF-8?q?=E4=B8=BA=E6=AD=A3=E5=B8=B8=E8=BF=94=E5=9B=9E=EF=BC=8C=E4=BD=86?= =?UTF-8?q?=E6=98=AF=E6=89=80=E6=9C=89=E7=9A=84=E5=8A=A0=E9=80=9F=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=E5=8F=88=E6=B2=A1=E6=9C=89=E8=B0=83=E7=94=A8=E5=AE=8C?= =?UTF-8?q?=E6=AF=95=E5=AF=BC=E8=87=B4=E7=9A=84=E6=8F=92=E4=BB=B6=E5=95=86?= =?UTF-8?q?=E5=BA=97=E7=BB=8F=E5=B8=B8=E6=8A=A5=E9=94=99302=E5=BC=82?= =?UTF-8?q?=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zhenxun/builtin_plugins/plugin_store/data_source.py | 4 ++-- zhenxun/utils/http_utils.py | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/zhenxun/builtin_plugins/plugin_store/data_source.py b/zhenxun/builtin_plugins/plugin_store/data_source.py index 6e662a81..c7d63f1a 100644 --- a/zhenxun/builtin_plugins/plugin_store/data_source.py +++ b/zhenxun/builtin_plugins/plugin_store/data_source.py @@ -91,8 +91,8 @@ class ShopManage: "plugins.json" ) extra_github_url = await extra_github_repo.get_raw_download_urls("plugins.json") - res = await AsyncHttpx.get(default_github_url) - res2 = await AsyncHttpx.get(extra_github_url) + res = await AsyncHttpx.get(default_github_url,check_status_code=200) + res2 = await AsyncHttpx.get(extra_github_url,check_status_code=200) # 检查请求结果 if res.status_code != 200 or res2.status_code != 200: diff --git a/zhenxun/utils/http_utils.py b/zhenxun/utils/http_utils.py index 962c9e01..8d19d132 100644 --- a/zhenxun/utils/http_utils.py +++ b/zhenxun/utils/http_utils.py @@ -43,6 +43,7 @@ class AsyncHttpx: use_proxy: bool = True, proxy: dict[str, str] | None = None, timeout: int = 30, # noqa: ASYNC109 + check_status_code: int | None = None, **kwargs, ) -> Response: """Get @@ -56,6 +57,7 @@ class AsyncHttpx: use_proxy: 使用默认代理 proxy: 指定代理 timeout: 超时时间 + check_status_code: 检查状态码 """ urls = [url] if isinstance(url, str) else url return await cls._get_first_successful( @@ -67,6 +69,7 @@ class AsyncHttpx: use_proxy=use_proxy, proxy=proxy, timeout=timeout, + check_status_code=check_status_code, **kwargs, ) @@ -74,12 +77,17 @@ class AsyncHttpx: async def _get_first_successful( cls, urls: list[str], + check_status_code: int | None = None, **kwargs, ) -> Response: last_exception = None for url in urls: try: - return await cls._get_single(url, **kwargs) + logger.info(f"开始获取 {url}..") + response = await cls._get_single(url, **kwargs) + if check_status_code and response.status_code != check_status_code: + raise Exception(f"Status code error: {response.status_code} != {check_status_code}") + return response except Exception as e: last_exception = e if url != urls[-1]: