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)