Spaces:
Paused
Paused
| """ | |
| Utilidades compartidas para scrapers — CrowData. | |
| SSL verification: | |
| - Por defecto, verificar SSL (seguro). | |
| - Algunos sitios .gob.ar tienen certificados rotos/viejos. | |
| - Usar create_client() que maneja fallback automático. | |
| """ | |
| import logging | |
| import httpx | |
| logger = logging.getLogger(__name__) | |
| # Sitios conocidos con problemas de SSL (certificados viejos, auto-firmados, etc.) | |
| # Agregar aquí cuando se descubra que un sitio falla con verify=True | |
| SSL_EXEMPTIONS = { | |
| "boletinoficial.gob.ar", | |
| "servicioscf.afip.gob.ar", | |
| "rgaconsultas.afip.gob.ar", | |
| "app.afip.gob.ar", | |
| "radicaciones.anses.gob.ar", | |
| "oficinavirtualpersonas.anses.gob.ar", | |
| "scjn.gov.ar", | |
| "carto.arba.gob.ar", | |
| "consultas.arba.gob.ar", | |
| "arba.gov.ar", | |
| } | |
| def _needs_ssl_exemption(url: str) -> bool: | |
| """Chequea si la URL pertenece a un dominio con problemas conocidos de SSL.""" | |
| for domain in SSL_EXEMPTIONS: | |
| if domain in url: | |
| return True | |
| return False | |
| async def create_http_client( | |
| timeout: int = 30, | |
| follow_redirects: bool = True, | |
| proxy: str | None = None, | |
| force_verify: bool | None = None, | |
| **kwargs, | |
| ) -> httpx.AsyncClient: | |
| """ | |
| Crea un httpx.AsyncClient con SSL verification inteligente. | |
| - force_verify=True: siempre verificar SSL | |
| - force_verify=False: nunca verificar SSL | |
| - force_verify=None (default): verificar SSL, excepto para dominios conocidos rotos | |
| """ | |
| if force_verify is not None: | |
| verify = force_verify | |
| else: | |
| verify = True # Default: verificar | |
| client = httpx.AsyncClient( | |
| timeout=timeout, | |
| follow_redirects=follow_redirects, | |
| verify=verify, | |
| proxy=proxy, | |
| **kwargs, | |
| ) | |
| if verify: | |
| logger.debug("[HTTP] SSL verification habilitado") | |
| else: | |
| logger.debug("[HTTP] SSL verification DESHABILITADO (excepción)") | |
| return client | |