19

I'm trying to write a simple server in python. I'm trying to import a few modules:

from http.server import HTTPServer
from http.server import SimpleHTTPServer

Because the doc says it has been moved.

But it gives me this error : from http.server import SimpleHTTPServer ImportError: cannot import name 'SimpleHTTPServer'

And without SimpleHTTPServer I can't use SimpleHTTPRequestHandler, as it is defined in SimpleHTTPServer.SimpleHTTPRequestHandler.

3
  • 4
    The SimpleHTTPServer was moved to be the module http.server. You want to use the request handler class BaseHTTPRequestHandler. From the docs. Commented Feb 19, 2020 at 17:37
  • 2
    If you're using Python 3 it's probably best to refer to those docs, not the ones for Python 2. Commented Feb 19, 2020 at 17:38
  • This question is similar to: What is the Python 3 equivalent of "python -m SimpleHTTPServer". If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. Commented Jul 5 at 2:24

2 Answers 2

33

The SimpleHTTPServer module was moved to be the module http.server. So the command is:

python3 -m http.server

Also, the new SimpleHTTPRequestHandler object is BaseHTTPRequestHandler.

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

Comments

3

My solution was:

python -m http.server

If I type python3 on the console is printed "Python not found". (I'm on Windows)

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

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.