mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
适配 httpx 0.28.0+版本
This commit is contained in:
parent
58a02c0555
commit
3eefa17a82
@ -25,33 +25,16 @@ from zhenxun.utils.user_agent import get_user_agent
|
|||||||
|
|
||||||
|
|
||||||
def get_async_client(proxies=None, **kwargs):
|
def get_async_client(proxies=None, **kwargs):
|
||||||
from httpx._config import create_ssl_context
|
transport = httpx.AsyncHTTPTransport(verify=False)
|
||||||
|
|
||||||
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
|
|
||||||
try:
|
try:
|
||||||
return httpx.AsyncClient(proxies=proxies, **kwargs)
|
return httpx.AsyncClient(proxies=proxies, transport=transport, **kwargs)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
return httpx.AsyncClient(
|
return httpx.AsyncClient(mounts={
|
||||||
mounts={
|
k: v for k, v in {
|
||||||
k: v
|
"http://": httpx.AsyncHTTPTransport(proxy=proxies.get("http")) if proxies else None,
|
||||||
for k, v in {
|
"https://": httpx.AsyncHTTPTransport(proxy=proxies.get("https")) if proxies else None
|
||||||
"http://": httpx.AsyncHTTPTransport(proxy=proxies.get("http"))
|
}.items() if v is not None
|
||||||
if proxies
|
}, transport=transport, **kwargs)
|
||||||
else None,
|
|
||||||
"https://": httpx.AsyncHTTPTransport(proxy=proxies.get("https"))
|
|
||||||
if proxies
|
|
||||||
else None,
|
|
||||||
}.items()
|
|
||||||
if v is not None
|
|
||||||
},
|
|
||||||
**kwargs,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class AsyncHttpx:
|
class AsyncHttpx:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user