在部分请求中使用httpx替换aiohttp

This commit is contained in:
KimigaiiWuyi 2024-02-05 04:37:57 +08:00
parent cf2e874e7e
commit bc93c66bc6

View File

@ -21,6 +21,7 @@ from typing import (
overload,
)
import httpx
from aiohttp import TCPConnector, ClientSession, ContentTypeError
from gsuid_core.logger import logger
@ -387,9 +388,7 @@ class BaseMysApi:
else:
proxy = None
async with ClientSession(
connector=TCPConnector(verify_ssl=ssl_verify)
) as client:
async with httpx.AsyncClient(verify=ssl_verify, proxy=proxy) as client:
raw_data = {}
uid = None
if params and 'role_id' in params:
@ -417,19 +416,18 @@ class BaseMysApi:
logger.debug(header)
for _ in range(2):
async with client.request(
resp = await client.request(
method,
url=url,
headers=header,
params=params,
json=data,
proxy=proxy,
timeout=300,
) as resp:
)
try:
raw_data = await resp.json()
raw_data = resp.json()
except ContentTypeError:
_raw_data = await resp.text()
_raw_data = resp.text
raw_data = {'retcode': -999, 'data': _raw_data}
logger.debug(raw_data)