File size: 724 Bytes
345855e | 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 33 34 35 36 37 38 | import httpx
import asyncio
async def request(
method,
url,
headers=None,
data=None,
json=None,
files=None,
retries=3,
):
for attempt in range(retries):
try:
async with httpx.AsyncClient(timeout=120) as client:
r = await client.request(
method,
url,
headers=headers,
data=data,
json=json,
files=files,
)
r.raise_for_status()
return r.json()
except Exception as e:
if attempt == retries - 1:
raise
await asyncio.sleep(2 ** attempt) |