From d6d54175f6613f2fa8e906c761c3c5de1dcfcaed Mon Sep 17 00:00:00 2001 From: molanp <104612722+molanp@users.noreply.github.com> Date: Tue, 17 Jun 2025 19:51:24 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=91=20=E4=BF=AE=E5=A4=8D=E4=BB=A3?= =?UTF-8?q?=E7=90=86=E8=AE=BE=E7=BD=AE=E9=97=AE=E9=A2=98=20(#1928)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zhenxun/utils/http_utils.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/zhenxun/utils/http_utils.py b/zhenxun/utils/http_utils.py index 62bce808..2ac982c4 100644 --- a/zhenxun/utils/http_utils.py +++ b/zhenxun/utils/http_utils.py @@ -7,7 +7,7 @@ from typing import Any, ClassVar, Literal, cast import aiofiles import httpx -from httpx import AsyncHTTPTransport, HTTPStatusError, Response +from httpx import AsyncHTTPTransport, HTTPStatusError, Proxy, Response from nonebot_plugin_alconna import UniMessage from nonebot_plugin_htmlrender import get_browser from playwright.async_api import Page @@ -34,14 +34,15 @@ def get_async_client( if proxies: http_proxy = proxies.get("http://") https_proxy = proxies.get("https://") - transport_kwargs = {} - if http_proxy: - transport_kwargs["http"] = http_proxy - if https_proxy: - transport_kwargs["https"] = https_proxy - proxy_transport = AsyncHTTPTransport(**transport_kwargs) return httpx.AsyncClient( - mounts={"http://": proxy_transport, "https://": proxy_transport}, + mounts={ + "http://": AsyncHTTPTransport( + proxy=Proxy(http_proxy) if http_proxy else None + ), + "https://": AsyncHTTPTransport( + proxy=Proxy(https_proxy) if https_proxy else None + ), + }, transport=transport, **kwargs, )