File size: 4,835 Bytes
9e4bb05 | 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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | # 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:
```bash
# 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:**
```bash
# 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:**
```bash
# 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:**
```bash
# 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:**
```bash
# 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:
```bash
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:
```javascript
// 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)
```bash
# 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
```bash
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
|