SimpleHTTPServer not found python3
Asked Answered
E

2

15

I'm trying to write a simple server in python. So after watching tutorial, I'm trying to import a few modules.

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

As the doc says, it has been moved, that's why i'm doing so.

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.

How can I resolve this ?

Egress answered 19/2, 2020 at 17:34 Comment(3)
The SimpleHTTPServer was moved to be the module http.server. You want to use the request handler class BaseHTTPRequestHandler. From the docs.Mannikin
If you're using Python 3 it's probably best to refer to those docs, not the ones for Python 2.Bounteous
thanks.. it worked ... you should post it as answer.. @MannikinEgress
M
27

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.

Mannikin answered 19/2, 2020 at 17:42 Comment(0)
M
2

My solution was:

python -m http.server

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

Meteorite answered 10/8, 2022 at 10:48 Comment(1)
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.Polaris

© 2022 - 2024 — McMap. All rights reserved.