ModuleNotFoundError: No module named 'BaseHTTPServer'

Question:

So I am trying to follow a tutorial online on how to work with web.py, and I got it installed but unfortunately, using this piece of code yields a nasty error.
My Code…

import web

urls = (
    '/(.*)', 'index'
)

app = web.application(urls, globals())


class index:
    def GET(self, name):
        return "Hello", name, '. How are you today?'

if __name__== "__main__":
    app.run()

MY ERROR:

C:UsersUserAppDataLocalProgramsPythonPython36-32python.exe C:/Users/User/PycharmProjects/Webprojects/main.py

Traceback (most recent call last):
  File "C:/Users/User/PycharmProjects/Webprojects/main.py", line 15, in <module>
    app.run()
  File "C:UsersUserAppDataLocalProgramsPythonPython36-32libsite-packageswebapplication.py", line 312, in run
    return wsgi.runwsgi(self.wsgifunc(*middleware))
  File "C:UsersUserAppDataLocalProgramsPythonPython36-32libsite-packageswebwsgi.py", line 59, in runwsgi
    return httpserver.runsimple(func, server_addr)
  File "C:UsersUserAppDataLocalProgramsPythonPython36-32libsite-packageswebhttpserver.py", line 154, in runsimple
    func = LogMiddleware(func)
  File "C:UsersUserAppDataLocalProgramsPythonPython36-32libsite-packageswebhttpserver.py", line 296, in __init__
    from BaseHTTPServer import BaseHTTPRequestHandler
ModuleNotFoundError: No module named 'BaseHTTPServer'

Process finished with exit code 1
Asked By: christopherson

||

Answers:

That import line won’t work in Python 3 which moved BaseHTTPServer to http.server

In your specific case you should update web.py to the current version that works with Python 3.

Answered By: Nathan V
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.