From f9b705aedd831006552e5218b8480edc6dda537a Mon Sep 17 00:00:00 2001 From: HibiKier <775757368@qq.com> Date: Tue, 19 Aug 2025 16:17:06 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E6=9B=B4=E6=96=B0=20get=5Fasync=5F?= =?UTF-8?q?client=20=E5=87=BD=E6=95=B0=EF=BC=8C=E6=94=AF=E6=8C=81=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E4=B8=B2=E7=B1=BB=E5=9E=8B=E7=9A=84=E4=BB=A3=E7=90=86?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改 proxies 参数类型,允许传入字符串形式的代理地址 - 增强代理处理逻辑,将字符串代理转换为字典格式,提升灵活性和可用性 --- zhenxun/utils/http_utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/zhenxun/utils/http_utils.py b/zhenxun/utils/http_utils.py index 35cae869..202e732e 100644 --- a/zhenxun/utils/http_utils.py +++ b/zhenxun/utils/http_utils.py @@ -98,7 +98,7 @@ def get_client() -> AsyncClient: def get_async_client( - proxies: dict[str, str] | None = None, + proxies: dict[str, str] | str | None = None, proxy: str | None = None, verify: bool = False, **kwargs, @@ -109,6 +109,8 @@ def get_async_client( """ transport = kwargs.pop("transport", None) or AsyncHTTPTransport(verify=verify) if proxies: + if isinstance(proxies, str): + proxies = {"http://": proxies, "https://": proxies} http_proxy = proxies.get("http://") https_proxy = proxies.get("https://") return httpx.AsyncClient(