blob: d16c17b9ed9a2515bf4c99d2a3f3edf80787ed33 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
from typing import Optional
from aiohttp import ClientSession
async def get_text(url: str, headers: Optional[dict] = None) -> str:
async with ClientSession() as session:
async with session.get(url, headers=headers) as r:
result = await r.text()
return result
async def get_bytes(url: str, headers: Optional[dict] = None) -> bytes:
async with ClientSession() as session:
async with session.get(url, headers=headers) as r:
result = await r.read()
return result
async def get_content(url: str, headers: Optional[dict] = None):
async with ClientSession() as session:
async with session.get(url, headers=headers) as r:
result = await r.content.read()
return result
async def post_bytes(
url: str, params: Optional[dict] = None, json: Optional[dict] = None
) -> bytes:
async with ClientSession() as session:
async with session.post(url, params=params, json=json) as r:
result = await r.read()
return result
|