22

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:\Users\User\AppData\Local\Programs\Python\Python36-32\python.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:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\site-packages\web\application.py", line 312, in run
    return wsgi.runwsgi(self.wsgifunc(*middleware))
  File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\site-packages\web\wsgi.py", line 59, in runwsgi
    return httpserver.runsimple(func, server_addr)
  File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\site-packages\web\httpserver.py", line 154, in runsimple
    func = LogMiddleware(func)
  File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\site-packages\web\httpserver.py", line 296, in __init__
    from BaseHTTPServer import BaseHTTPRequestHandler
ModuleNotFoundError: No module named 'BaseHTTPServer'

Process finished with exit code 1
anthony sottile
  • 61,815
  • 15
  • 148
  • 207
christopherson
  • 383
  • 3
  • 6
  • 20
  • It looks like that tutorial is based on Python version 2. Python 3 doesn't have a module named 'BaseHTTPServer'. see [this](https://docs.python.org/3/library/http.server.html) – Himal Jul 21 '17 at 04:41
  • I do not think you can use any tool to convert this. What you would need is a python3 version of web.py, see https://stackoverflow.com/questions/43791484/is-there-a-web-py-for-python3-yet . – Teemu Risikko Jul 21 '17 at 06:24

1 Answers1

25

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.

malajisi
  • 2,165
  • 1
  • 22
  • 18
Nathan V
  • 455
  • 7
  • 12