3

I've just tried to run python -m SimpleHTTPServer 8000 in a directory where I have some basic web files. It seems to run fine at first, on the command line it prints:

Serving HTTP on 0.0.0.0 port 8000 ...

However, when I try to view my page on http://127.0.0.1:8000 in browser, I get this error message:

A server error occurred. Please contact the administrator.

Sorry if this seems vague, but I'm not a Python developer so I have no idea why it's not working. Do you have any ideas why or how to start debugging this issue?

7
  • Any message on the command line? Commented Dec 29, 2013 at 18:53
  • @PauloBu nothing at all, it just displays the original Serving HTTP on 0.0.0.0 port 8000 ... Commented Dec 29, 2013 at 18:54
  • Have you tried running it in another port? Test 12345 for example. Commented Dec 29, 2013 at 18:55
  • Ah ha! That worked. I had an application open that was running another server on port 8000 that I had forgotten about. If you'd like to add as an answer below, I'll mark it as correct. If not I could delete this question if it's too simple. Commented Dec 29, 2013 at 18:57
  • Just delete it :) It was a simple mistake :) Glad I could help! :) Commented Dec 29, 2013 at 18:58

2 Answers 2

6

If you aren't seeing anything on the command line, then the server is not getting any input. You must have some other process listening on that port. Try a different port just to be sure:

python -m SimpleHTTPServer 12345

Just a tip, to check what applications you have listening on which port, netstat command can be very useful :)

Hope this helps!

Sign up to request clarification or add additional context in comments.

3 Comments

This works. What doesn't work is tryng to connect to http://{ip_address}:12345 (or whatever other port) with the browser (Firefox in my case). It simply can't connect. (Using just {ip_address} works.) Does it work for you? If yes, do you have any idea why not for someone else?
Wow, that's strange. I just tried it out verbatim and it worked with Chrome. Maybe your pc is not letting it bind to 0.0.0.0 (all interfaces). Try it with sudo. Didn't understand the part of "Using just {ip_address} works". What does it mean "works"?
By "just the IP address" I meant that 192.168.1.1 (my local IP address) works, so this is not the problem. But 192.168.1.1:1234 doesn't work. Neither 0.0.0.0:1234 does, which has no sense and I never saw using it in the examples I found around.
2

Try the following code for Python 3 version:

python -m http.server

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.