This commit is contained in:
2023-11-30 09:49:23 +03:00
parent 37f8dd2f53
commit 64db057706
3 changed files with 27 additions and 31 deletions

View File

@@ -1,24 +1,23 @@
from httpx import AsyncClient
import aiohttp
from settings import API_BASE
from typing import List, Any
from models.member import ChatMember
headers = {"Content-Type": "application/json"}
async def _request_endpoint(query_name, body) -> Any:
async with AsyncClient() as client:
async with aiohttp.ClientSession() as session:
try:
response = await client.post(API_BASE, headers=headers, json=body)
print(f"[services.core] {query_name}: [{response.status_code}] {len(response.text)} bytes")
if response.status_code != 200:
return []
r = response.json()
if r:
return r.get("data", {}).get(query_name, {})
else:
raise Exception("json response error")
async with session.post(API_BASE, headers=headers, json=body) as response:
print(f"[services.core] {query_name}: [{response.status}] {len(await response.text())} bytes")
if response.status != 200:
return []
r = await response.json()
if r:
return r.get("data", {}).get(query_name, {})
else:
raise Exception("json response error")
except Exception:
import traceback