mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
🚑 修复 httpx 初始化传参错误 (#1926)
This commit is contained in:
parent
62b0b02466
commit
ee9a2a6cb0
@ -25,6 +25,8 @@ from zhenxun.services.log import logger
|
|||||||
from zhenxun.utils.message import MessageUtils
|
from zhenxun.utils.message import MessageUtils
|
||||||
from zhenxun.utils.user_agent import get_user_agent
|
from zhenxun.utils.user_agent import get_user_agent
|
||||||
|
|
||||||
|
CLIENT_KEY = ["use_proxy", "proxy", "verify", "headers"]
|
||||||
|
|
||||||
|
|
||||||
def get_async_client(
|
def get_async_client(
|
||||||
proxies: dict[str, str] | None = None, verify: bool = False, **kwargs
|
proxies: dict[str, str] | None = None, verify: bool = False, **kwargs
|
||||||
@ -117,14 +119,11 @@ class AsyncHttpx:
|
|||||||
for current_url in urls:
|
for current_url in urls:
|
||||||
try:
|
try:
|
||||||
logger.info(f"开始获取 {current_url}..")
|
logger.info(f"开始获取 {current_url}..")
|
||||||
async with cls._create_client(**kwargs) as client:
|
client_kwargs = {k: v for k, v in kwargs.items() if k in CLIENT_KEY}
|
||||||
# 从 kwargs 中提取仅 client.get 支持的参数
|
for key in CLIENT_KEY:
|
||||||
get_kwargs = {
|
kwargs.pop(key, None)
|
||||||
k: v
|
async with cls._create_client(**client_kwargs) as client:
|
||||||
for k, v in kwargs.items()
|
response = await client.get(current_url, **kwargs)
|
||||||
if k not in ["use_proxy", "proxy", "verify", "headers"]
|
|
||||||
}
|
|
||||||
response = await client.get(current_url, **get_kwargs)
|
|
||||||
|
|
||||||
if check_status_code and response.status_code != check_status_code:
|
if check_status_code and response.status_code != check_status_code:
|
||||||
raise HTTPStatusError(
|
raise HTTPStatusError(
|
||||||
@ -155,13 +154,11 @@ class AsyncHttpx:
|
|||||||
返回:
|
返回:
|
||||||
Response: Response
|
Response: Response
|
||||||
"""
|
"""
|
||||||
async with cls._create_client(**kwargs) as client:
|
client_kwargs = {k: v for k, v in kwargs.items() if k in CLIENT_KEY}
|
||||||
head_kwargs = {
|
for key in CLIENT_KEY:
|
||||||
k: v
|
kwargs.pop(key, None)
|
||||||
for k, v in kwargs.items()
|
async with cls._create_client(**client_kwargs) as client:
|
||||||
if k not in ["use_proxy", "proxy", "verify"]
|
return await client.head(url, **kwargs)
|
||||||
}
|
|
||||||
return await client.head(url, **head_kwargs)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def post(cls, url: str, **kwargs) -> Response:
|
async def post(cls, url: str, **kwargs) -> Response:
|
||||||
@ -178,13 +175,11 @@ class AsyncHttpx:
|
|||||||
返回:
|
返回:
|
||||||
Response: Response。
|
Response: Response。
|
||||||
"""
|
"""
|
||||||
async with cls._create_client(**kwargs) as client:
|
client_kwargs = {k: v for k, v in kwargs.items() if k in CLIENT_KEY}
|
||||||
post_kwargs = {
|
for key in CLIENT_KEY:
|
||||||
k: v
|
kwargs.pop(key, None)
|
||||||
for k, v in kwargs.items()
|
async with cls._create_client(**client_kwargs) as client:
|
||||||
if k not in ["use_proxy", "proxy", "verify"]
|
return await client.post(url, **kwargs)
|
||||||
}
|
|
||||||
return await client.post(url, **post_kwargs)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def get_content(cls, url: str, **kwargs) -> bytes:
|
async def get_content(cls, url: str, **kwargs) -> bytes:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user