Download app/integrations/_base.py from Modulo-6/api: direct link, hf CLI and curl.
- Browser
- Download file 1.02 kB
-
https://huggingface.co/spaces/Modulo-6/api/resolve/ef45f33166da45a04d824b7904b284ef5aef70fe/app/integrations/_base.py
- Command line
-
hf download hf://spaces/Modulo-6/api@ef45f33166da45a04d824b7904b284ef5aef70fe/app/integrations/_base.py
-
curl -L -o _base.py https://huggingface.co/spaces/Modulo-6/api/resolve/ef45f33166da45a04d824b7904b284ef5aef70fe/app/integrations/_base.py
1.02 kB
| """ | |
| Helpers HTTP internos compartidos por todos los clientes de integración. | |
| """ | |
| import logging | |
| import httpx | |
| from app.config import settings | |
| logger = logging.getLogger(__name__) | |
| def _headers(token: str | None = None) -> dict: | |
| h = {"Content-Type": "application/json"} | |
| if token: | |
| h["Authorization"] = f"Bearer {token}" | |
| return h | |
| def _post(url: str, payload: dict, token: str | None = None) -> dict | None: | |
| try: | |
| r = httpx.post(url, json=payload, headers=_headers(token), timeout=settings.http_timeout_seconds) | |
| r.raise_for_status() | |
| return r.json() | |
| except Exception as e: | |
| logger.warning("Error en POST %s: %s", url, e) | |
| return None | |
| def _get(url: str, token: str | None = None) -> dict | None: | |
| try: | |
| r = httpx.get(url, headers=_headers(token), timeout=settings.http_timeout_seconds) | |
| r.raise_for_status() | |
| return r.json() | |
| except Exception as e: | |
| logger.warning("Error en GET %s: %s", url, e) | |
| return None | |