AndesOps-AI / TROUBLESHOOT.md
Álvaro Valenzuela Valdes
🚀 Production ready for HF Spaces (Security Cleaned)
9e4bb05

AndesAI - Troubleshooting Guide

✅ Checklist de Configuración

1. Backend Configuration

  • Backend está ejecutándose en http://localhost:8000
  • Base de datos SQLite está accesible en ./andesops.db
  • Variables de entorno configuradas en backend/.env:
    MERCADO_PUBLICO_TICKET=99B4CA8C-C1DF-4E3F-B5CF-C1672D432A91
    GEMINI_API_KEY=AIzaSyBidQBGcitskZaJZDQXUDNNSMjlSTF7jhQ
    DATABASE_URL=sqlite:///./andesops.db
    

2. Frontend Configuration

  • Frontend .env.local tiene:
    NEXT_PUBLIC_API_BASE=http://localhost:8000
    
  • Frontend está corriendo en desarrollo o producción

3. API Endpoints - Test Manual

Prueba estos endpoints en tu navegador o curl:

# Health check
curl http://localhost:8000/api/health

# Get tenders (busca en BD local)
curl "http://localhost:8000/api/tenders?skip=0&limit=10"

# Get tenders by keyword (busca en Mercado Público)
curl "http://localhost:8000/api/tenders?keyword=software"

# Scrape Compra Ágil (nuevo endpoint)
curl "http://localhost:8000/api/tenders/scrape?keyword=tecnologia"

# Get Purchase Orders (OC) - HOY
curl "http://localhost:8000/api/purchase-orders"

# Get Purchase Orders (OC) - Fecha específica
curl "http://localhost:8000/api/purchase-orders?date=06052026&status=todos"

🔧 Problemas Comunes

Problema: "Connection Error" en Market Monitor

Causas:

  1. Backend no está ejecutándose
  2. URL del API_BASE es incorrecta
  3. CORS bloqueado

Solución:

# 1. Inicia el backend
cd backend
python -m uvicorn app.main:app --reload --host 0.0.0.0 --port 8000

# 2. Verifica que esté respondiendo
curl http://localhost:8000/api/health

# 3. Si falla, revisa los logs del backend

Problema: Órdenes de Compra devuelven vacías

Causas:

  1. Ticket de Mercado Público expirado/inválido
  2. No hay OC publicadas hoy
  3. Error en la API de Mercado Público

Solución:

# Test directo de OC
curl "http://localhost:8000/api/purchase-orders"

# Test con fecha específica
curl "http://localhost:8000/api/purchase-orders?date=06052026"

# Verifica el ticket en backend/.env
echo $MERCADO_PUBLICO_TICKET  # Debe mostrar el ticket

Problema: "Compra Ágil" no trae resultados

Causas:

  1. Endpoint de Mercado Público devolvió error
  2. Keyword no tiene resultados
  3. API returns 500 (sin datos disponibles)

Solución:

# Test del scraper
curl "http://localhost:8000/api/tenders/scrape?keyword=tecnologia"

# Si falla, activará fallback sintético
# Verifica logs del backend: look for "[Scraper]" messages

Problema: Frontend no conecta con Backend

Diagnóstico:

  1. Abre Developer Tools (F12)
  2. Ve a Network tab
  3. Intenta hacer una búsqueda
  4. Busca peticiones fallidas

Soluciones:

# Verify frontend .env.local
cat frontend/.env.local
# Debe mostrar: NEXT_PUBLIC_API_BASE=http://localhost:8000

# Rebuild frontend if needed
cd frontend
npm run build
npm start

# Check if API_BASE is used in network requests
# Debe ver requests a http://localhost:8000/api/*

📋 Logs útiles para debugging

Backend Logs:

cd backend
python -m uvicorn app.main:app --reload

# Look for these messages:
# "[Scraper] 📡 Fetching..." - Scraper activo
# "✅ Success" - Búsqueda exitosa
# "⚠️ API blocked" - Error en API externa
# "❌ Scraper failure" - Fallback a datos sintéticos

Frontend Logs:

// En Developer Tools Console (F12)
// Look for:
// [API] messages - Llamadas API
// [TenderSearch] - Búsquedas de tenders
// Connection errors - Problemas de conexión

🚀 Como iniciar el sistema completo

Opción 1: Desarrollo Local (Recomendado)

# Terminal 1 - Backend
cd backend
python -m venv .venv
source .venv/bin/activate  # Windows: .venv\Scripts\activate
pip install -r requirements.txt
python -m uvicorn app.main:app --reload --port 8000

# Terminal 2 - Frontend
cd frontend
npm install
npm run dev
# Abre http://localhost:3000

Opción 2: Docker Compose

docker-compose up -d
# Backend en http://localhost:8000
# Frontend en http://localhost:3000

✨ Features que debería ver

  1. Tender Search Tab

    • ✅ Buscar por keyword
    • ✅ Filtrar por status, org, fecha
    • ✅ Compra Ágil scraping
  2. Market Monitor Tab

    • ✅ Ver órdenes de compra del día
    • ✅ Filtrar por estado
    • ✅ Mostrar montos totales
  3. Data Flow

    • Frontend → Backend (HTTP) → Mercado Público API → Response

📞 Si aún no funciona

  1. Verifica los logs en ambas terminales
  2. Asegúrate que el backend esté respondiendo a /api/health
  3. Verifica que NEXT_PUBLIC_API_BASE sea exactamente http://localhost:8000
  4. Limpia cache del navegador (Ctrl+Shift+R)
  5. Reinicia ambos servicios