Spaces:
Sleeping
Sleeping
Download utils.py from Jash-K/Dataset_Recommender: direct link, hf CLI and curl.
- Browser
- Download file 840 Bytes
-
https://huggingface.co/spaces/Jash-K/Dataset_Recommender/resolve/main/utils.py
- Command line
-
hf download hf://spaces/Jash-K/Dataset_Recommender/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/Jash-K/Dataset_Recommender/resolve/main/utils.py
840 Bytes
| import aiohttp | |
| import logging | |
| from typing import Any | |
| from tenacity import retry, stop_after_attempt, wait_exponential | |
| logging.basicConfig(level=logging.INFO) | |
| logger = logging.getLogger(__name__) | |
| async def async_fetch_json( | |
| url: str, | |
| headers: dict[str, str] | None = None, | |
| params: dict[str, Any] | None = None, | |
| timeout: int = 15 | |
| ) -> Any: | |
| async with aiohttp.ClientSession(headers=headers) as session: | |
| try: | |
| async with session.get(url, params=params, timeout=timeout) as response: | |
| response.raise_for_status() | |
| return await response.json() | |
| except Exception as e: | |
| logger.error(f"Fetch failed for {url}: {e}") | |
| raise |