Spaces:
Paused
Paused
Captain Ezio
commited on
Commit
·
46fb3e1
1
Parent(s):
553ca09
Update http_helper.py
Browse files- Powers/utils/http_helper.py +23 -20
Powers/utils/http_helper.py
CHANGED
|
@@ -1,33 +1,36 @@
|
|
| 1 |
from asyncio import gather
|
| 2 |
|
| 3 |
-
from Powers.bot_class import aiohttpsession as session
|
| 4 |
-
|
| 5 |
|
| 6 |
async def get(url: str, *args, **kwargs):
|
| 7 |
-
async with
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
| 13 |
|
| 14 |
|
| 15 |
async def head(url: str, *args, **kwargs):
|
| 16 |
-
async with
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
| 22 |
|
| 23 |
|
| 24 |
async def post(url: str, *args, **kwargs):
|
| 25 |
-
async with
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
| 31 |
|
| 32 |
|
| 33 |
async def multiget(url: str, times: int, *args, **kwargs):
|
|
|
|
| 1 |
from asyncio import gather
|
| 2 |
|
| 3 |
+
# from Powers.bot_class import aiohttpsession as session
|
| 4 |
+
from aiohttp import ClientSession as session
|
| 5 |
|
| 6 |
async def get(url: str, *args, **kwargs):
|
| 7 |
+
async with aiohttp.ClientSession() as session:
|
| 8 |
+
async with session.get(url, *args, **kwargs) as resp:
|
| 9 |
+
try:
|
| 10 |
+
data = await resp.json()
|
| 11 |
+
except Exception:
|
| 12 |
+
data = await resp.text()
|
| 13 |
+
return data
|
| 14 |
|
| 15 |
|
| 16 |
async def head(url: str, *args, **kwargs):
|
| 17 |
+
async with aiohttp.ClientSession() as session:
|
| 18 |
+
async with session.head(url, *args, **kwargs) as resp:
|
| 19 |
+
try:
|
| 20 |
+
data = await resp.json()
|
| 21 |
+
except Exception:
|
| 22 |
+
data = await resp.text()
|
| 23 |
+
return data
|
| 24 |
|
| 25 |
|
| 26 |
async def post(url: str, *args, **kwargs):
|
| 27 |
+
async with aiohttp.ClientSession() as session:
|
| 28 |
+
async with session.post(url, *args, **kwargs) as resp:
|
| 29 |
+
try:
|
| 30 |
+
data = await resp.json()
|
| 31 |
+
except Exception:
|
| 32 |
+
data = await resp.text()
|
| 33 |
+
return data
|
| 34 |
|
| 35 |
|
| 36 |
async def multiget(url: str, times: int, *args, **kwargs):
|