# Troubleshooting - Cannot Submit Exam ## Issue Getting "Not Found" errors when trying to autosave or submit exam. ## Root Cause The backend server needs to be properly initialized with migrations and sessions. When you start an exam before the backend is fully ready, the session may not persist correctly. ## Solution 1: Refresh and Restart Exam (Recommended) ### Step 1: Restart Backend ```bash cd exam_system docker-compose restart exam_server ``` ### Step 2: Clear Browser Data 1. Open browser console (F12) 2. Go to Application > Storage 3. Clear all cookies and localStorage 4. Or just open an incognito/private window ### Step 3: Start Fresh 1. Refresh the page (or open http://localhost in incognito) 2. Click "Start Exam" again 3. Answer questions 4. Submit should work now ## Solution 2: Complete Restart ```bash cd exam_system # Stop all containers docker-compose down # Start fresh docker-compose up -d # Wait 10 seconds for services to start sleep 10 # Run migrations docker-compose exec exam_server python manage.py migrate # Now open browser to http://localhost ``` ## Solution 3: Manual Test via API Test if the API is working: ```bash # Get session cookie first curl -c cookies.txt http://localhost/api/exams/ # Start attempt curl -b cookies.txt -X POST http://localhost/api/exams/python-basics-v1/attempt/ # The response will show the attemptId # Use it to test autosave (replace ATTEMPT_ID): curl -b cookies.txt -X PUT \ -H "Content-Type: application/json" \ -d '{"answers":[{"questionId":"q1","response":"C","timeSec":30}]}' \ http://localhost/api/attempts/ATTEMPT_ID/autosave/ # Submit (replace ATTEMPT_ID): curl -b cookies.txt -X POST \ http://localhost/api/attempts/ATTEMPT_ID/submit/ ``` ## Verify System is Ready Before starting an exam, check: ```bash # All containers running docker-compose ps # Backend healthy curl http://localhost/api/health/ # Exams available curl http://localhost/api/exams/ # Check logs for errors docker-compose logs --tail=20 exam_server ``` All should return valid responses with no errors. ## Common Issues ### 1. "Not Found" for autosave/submit **Symptom:** Console shows 404 errors for `/api/attempts/.../autosave/` **Fix:** - Backend wasn't ready when you started - Restart backend: `docker-compose restart exam_server` - Clear browser cookies - Try again ### 2. "django.db.utils.OperationalError: no such table" **Symptom:** Logs show database table errors **Fix:** ```bash docker-compose exec exam_server python manage.py migrate docker-compose restart exam_server ``` ### 3. Session expired **Symptom:** Autosave stops working after some time **Fix:** - Sessions expire after 24 hours - Refresh page and start new attempt - Or increase SESSION_COOKIE_AGE in settings ### 4. CORS errors **Symptom:** Console shows CORS policy errors **Fix:** - Check nginx is routing correctly - Verify all containers are running - Restart: `docker-compose restart` ## Debug Mode Enable detailed logging: ```bash # Edit docker-compose.yml # Change DEBUG=True (it's already True in dev) # View live logs docker-compose logs -f exam_server docker-compose logs -f exam_web ``` ## Manual Submission If all else fails, you can manually create the output: ```bash # Your attempt file ATTEMPT_FILE="data/attempts/user_default/python-basics-v1/[YOUR_ATTEMPT_ID].json" # Your exam file EXAM_FILE="data/input/python-basics-v1.json" # Create output manually python3 << 'EOF' import json with open('ATTEMPT_FILE') as f: attempt = json.load(f) with open('EXAM_FILE') as f: exam = json.load(f) bundle = {"exam": exam, "attempt": attempt} with open(f"data/output/{exam['examId']}_{attempt['attemptId']}.json", 'w') as f: json.dump(bundle, f, indent=2) print("Bundle created!") EOF ``` ## Prevention To avoid this issue: 1. **Always wait for services to be ready** ```bash docker-compose up -d sleep 10 # Wait for startup docker-compose exec exam_server python manage.py migrate ``` 2. **Check health before using** ```bash curl http://localhost/api/health/ ``` 3. **Use incognito window** for clean sessions 4. **Don't restart backend** while taking an exam ## Test Submission Working After fixing, test with: 1. Open http://localhost 2. Open browser console (F12) 3. Start exam 4. Watch Network tab 5. You should see: - `POST /api/exams/python-basics-v1/attempt/` → 200 or 201 - `PUT /api/attempts/.../autosave/` → 200 (every 10 sec) - `POST /api/attempts/.../submit/` → 200 All should return 200 status codes. ## Still Not Working? Contact support or check: - `docker-compose logs exam_server` - `docker-compose logs nginx` - Browser console errors - Network tab in dev tools