2 min read · 461 words
If you have ever run into a sudden 404 Not Found on a previously working FastAPI endpoint, you know how frustrating it can be. Here is how I tracked down and resolved a FastAPI 404 error caused by accidentally archiving active routers during a module cleanup.
The Problem
I was trying to get the inspector card on the index tab to display the current inspector state. Instead of rendering the data, the UI broke, throwing a FastAPI 404 error.
Symptoms
During a Chrome MCP visual sweep, I noticed the `/api/inspector/state` endpoint was returning a 404. The index card displayed a clear error: `Inspector 상태 로드 실패: inspector state HTTP 404`. Our internal smoke-test loop didn't catch this pre-deployment because the inspector wasn't included in its target list.
Environment
This is a standard FastAPI webapp. I had recently pruned some legacy `sess140` modules, moving the target files into the `_archive/sess140-prune/` directory.
What Didn't Work
I tried restarting the webapp, hoping it was a transient caching issue. No luck—the 404 persisted.
Root Cause & Resolution
The culprit was the `sess140` pruning process. I had accidentally moved `webapp/routers/inspector.py` and `webapp/seo/inspector.py` into the archive folder. Because we had a `_NullModule` stub in place, the router itself initialized without throwing an import error, but it had 0 active routes mapped to it—hence the silent 404. I restored both files from the archive to their original locations.
It turns out I got a bit too aggressive with the code cleanup and cut out the heart of the module. Lesson learned: double-check dependencies before pruning, and always keep a structured archive.
Commands Used
Here are the commands I used to restore the missing modules from the archive:
# Restore missing inspector modules from archive
cp _archive/sess140-prune/inspector.py webapp/routers/
cp _archive/sess140-prune/seo/inspector.py webapp/seo/Verification
After restoring the files, I restarted the webapp. A quick request to `/api/inspector/state` returned an HTTP 200. The router's route count went back up to 6 endpoints, and the index tab card is rendering perfectly. Status: Fixed.
Takeaway
If a FastAPI endpoint suddenly starts throwing 404s after a refactor, check your recent cleanup history first. Watch out for stub modules that might silently swallow import errors and leave you with empty router shells.
Category Coverage Notice
This article follows our label-specific editorial criteria. Details: