执行python -m http.server后无法访问127.0.0.1:8000的问题求助
python -m http.server Access Issues Hey there, let's work through why your local server isn't loading even though the console says it started on port 8000. I've hit this exact snag a few times, so here are the most common fixes to try out:
Verify the server is actually listening on port 8000
Sometimes the initial console message can be misleading, or another process might have grabbed the port. Run these commands to check:- On macOS/Linux:
lsof -i :8000 - On Windows:
netstat -an | findstr :8000
You should see a Python process listed as using the port. If not, restart the server and watch closely for any hidden error messages that might have flashed by.
- On macOS/Linux:
Check your firewall settings
Local firewalls (like Windows Defender Firewall or macOS Security & Privacy) often block incoming requests to non-standard ports like 8000. Try temporarily disabling your firewall and reloading127.0.0.1:8000—if it works, add an exception for Python or port 8000 to your firewall rules.Explicitly bind the server to all interfaces
By default,http.servershould listen on all local network interfaces (0.0.0.0), but system quirks or older Python versions can sometimes mess this up. Restart the server with this command to force it to listen to every local address:python -m http.server 8000 --bind 0.0.0.0Then try accessing
127.0.0.1:8000again.Rule out browser or proxy interference
Browsers can cache failed requests, so try loading the address in incognito/private mode. If you're using a proxy (either browser-level or system-wide), disable it temporarily—proxies often don't route local127.0.0.1requests correctly.Confirm you're using the right Python version
If you have both Python 2 and 3 installed, mixing commands can cause issues. For Python 2, the correct command ispython -m SimpleHTTPServer 8000; for Python 3, it'spython -m http.server 8000. Runpython --versionorpython3 --versionto check which one you're using, then use the matching command.Make sure the server process is still running
Double-check your console window—sometimes the server might crash silently after the initial "started" message (e.g., if it can't read a file in your current directory). If the console is closed or the process terminated, restart it and watch for any error output.
Start with the first couple of checks since they're the quickest to test—chances are one of these will get your server up and accessible!
内容的提问来源于stack exchange,提问作者Arya Drj




