mirror of
https://github.com/yasirarism/MissKatyPyro.git
synced 2025-12-29 17:44:50 +00:00
Fix http helper
This commit is contained in:
parent
efe8905ef1
commit
8837cdeed0
1 changed files with 18 additions and 23 deletions
|
|
@ -1,14 +1,9 @@
|
||||||
from asyncio import gather
|
from asyncio import gather
|
||||||
|
|
||||||
from aiohttp import ClientSession
|
|
||||||
from httpx import AsyncClient, Timeout
|
from httpx import AsyncClient, Timeout
|
||||||
|
|
||||||
# Aiohttp Async Client
|
|
||||||
# session = ClientSession()
|
|
||||||
|
|
||||||
# HTTPx Async Client
|
# HTTPx Async Client
|
||||||
fetch = AsyncClient(
|
fetch = AsyncClient(
|
||||||
http2=True,
|
https2=True
|
||||||
verify=False,
|
verify=False,
|
||||||
headers={
|
headers={
|
||||||
"Accept-Language": "en-US,en;q=0.9,id-ID;q=0.8,id;q=0.7",
|
"Accept-Language": "en-US,en;q=0.9,id-ID;q=0.8,id;q=0.7",
|
||||||
|
|
@ -19,29 +14,29 @@ fetch = AsyncClient(
|
||||||
|
|
||||||
|
|
||||||
async def get(url: str, *args, **kwargs):
|
async def get(url: str, *args, **kwargs):
|
||||||
async with session.get(url, *args, **kwargs) as resp:
|
try:
|
||||||
try:
|
resp = await fetch.get(url, *args, **kwargs)
|
||||||
data = await resp.json()
|
data = await resp.json()
|
||||||
except Exception:
|
except Exception:
|
||||||
data = await resp.text()
|
data = await resp.text()
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
async def head(url: str, *args, **kwargs):
|
async def head(url: str, *args, **kwargs):
|
||||||
async with session.head(url, *args, **kwargs) as resp:
|
try:
|
||||||
try:
|
resp = await fetch.head(url, *args, **kwargs)
|
||||||
data = await resp.json()
|
data = await resp.json()
|
||||||
except Exception:
|
except Exception:
|
||||||
data = await resp.text()
|
data = await resp.text()
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
async def post(url: str, *args, **kwargs):
|
async def post(url: str, *args, **kwargs):
|
||||||
async with session.post(url, *args, **kwargs) as resp:
|
try:
|
||||||
try:
|
resp = await fetch.post(url, *args, **kwargs)
|
||||||
data = await resp.json()
|
data = await resp.json()
|
||||||
except Exception:
|
except Exception:
|
||||||
data = await resp.text()
|
data = await resp.text()
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -58,8 +53,8 @@ async def multipost(url: str, times: int, *args, **kwargs):
|
||||||
|
|
||||||
|
|
||||||
async def resp_get(url: str, *args, **kwargs):
|
async def resp_get(url: str, *args, **kwargs):
|
||||||
return await session.get(url, *args, **kwargs)
|
return await fetch.get(url, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
async def resp_post(url: str, *args, **kwargs):
|
async def resp_post(url: str, *args, **kwargs):
|
||||||
return await session.post(url, *args, **kwargs)
|
return await fetch.post(url, *args, **kwargs)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue