Spaces:
Paused
Paused
File size: 1,909 Bytes
4223796 | 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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | """
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
|