zhenxun_bot/plugins/alapi/util.py

17 lines
653 B
Python
Raw Normal View History

2021-06-24 15:32:06 +08:00
import aiohttp
from util.utils import get_local_proxy
async def get_data(url: str, params: dict):
async with aiohttp.ClientSession() as session:
try:
async with session.get(url, proxy=get_local_proxy(), timeout=2, params=params) as response:
data = await response.json()
if data['code'] == 200:
if not data['data']:
return '没有搜索到...', 997
return data, 200
else:
return f'发生了错误...code{data["code"]}', 999
except TimeoutError:
return '超时了....', 998