【问题标题】:ModuleNotFoundError: No module named 'BaseHTTPServer'ModuleNotFoundError:没有名为“BaseHTTPServer”的模块
【发布时间】:2017-12-26 23:54:21
【问题描述】:

所以我正在尝试按照在线教程了解如何使用 web.py,并且我已经安装了它,但不幸的是,使用这段代码会产生一个令人讨厌的错误。 我的代码...

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()

我的错误:

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

【问题讨论】:

  • 看起来该教程基于 Python 版本 2。Python 3 没有名为“BaseHTTPServer”的模块。见this
  • 我不认为你可以使用任何工具来转换它。您需要的是 web.py 的 python3 版本,请参阅stackoverflow.com/questions/43791484/…。

标签: python web.py python-3.6


【解决方案1】:

该导入行在将 BaseHTTPServer 移动到 http.server.HTTPServer 的 Python 3 中不起作用

在您的具体情况下,您应该将 web.py 更新为适用于 Python 3 的当前版本。

【讨论】:

  • 我得到“ModuleNotFoundError: No module named 'http.server.HTTPServer'; 'http.server' is not a package”
  • 有效的是使用 http.server 而不是 BaseHTTPServer
猜你喜欢
  • 2019-03-28
  • 2022-01-07
  • 2017-12-14
  • 2020-12-10
  • 2021-09-02
  • 2020-10-10
  • 2022-01-06
  • 2021-09-10
相关资源
最近更新 更多