Captain Ezio commited on
Commit
9dc9174
·
1 Parent(s): 2663246

Update http_helper.py

Browse files
Files changed (1) hide show
  1. 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 session.get(url, *args, **kwargs) as resp:
8
- try:
9
- data = await resp.json()
10
- except Exception:
11
- data = await resp.text()
12
- return data
 
13
 
14
 
15
  async def head(url: str, *args, **kwargs):
16
- async with session.head(url, *args, **kwargs) as resp:
17
- try:
18
- data = await resp.json()
19
- except Exception:
20
- data = await resp.text()
21
- return data
 
22
 
23
 
24
  async def post(url: str, *args, **kwargs):
25
- async with session.post(url, *args, **kwargs) as resp:
26
- try:
27
- data = await resp.json()
28
- except Exception:
29
- data = await resp.text()
30
- return data
 
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):