适配 httpx 0.28.0+版本

This commit is contained in:
molanp 2025-06-05 20:16:56 +08:00
parent 58a02c0555
commit 3eefa17a82

View File

@ -25,33 +25,16 @@ from zhenxun.utils.user_agent import get_user_agent
def get_async_client(proxies=None, **kwargs):
from httpx._config import create_ssl_context
context = create_ssl_context(
verify=kwargs.get("verify", True),
cert=kwargs.get("cert"),
trust_env=kwargs.get("trust_env", True),
)
context.set_ciphers("DEFAULT")
kwargs["verify"] = context
transport = httpx.AsyncHTTPTransport(verify=False)
try:
return httpx.AsyncClient(proxies=proxies, **kwargs)
return httpx.AsyncClient(proxies=proxies, transport=transport, **kwargs)
except TypeError:
return httpx.AsyncClient(
mounts={
k: v
for k, v in {
"http://": httpx.AsyncHTTPTransport(proxy=proxies.get("http"))
if proxies
else None,
"https://": httpx.AsyncHTTPTransport(proxy=proxies.get("https"))
if proxies
else None,
}.items()
if v is not None
},
**kwargs,
)
return httpx.AsyncClient(mounts={
k: v for k, v in {
"http://": httpx.AsyncHTTPTransport(proxy=proxies.get("http")) if proxies else None,
"https://": httpx.AsyncHTTPTransport(proxy=proxies.get("https")) if proxies else None
}.items() if v is not None
}, transport=transport, **kwargs)
class AsyncHttpx: