Python 属性错误:模块';http.server';没有属性';ThreadingHTTPServer';
我正在试用Python3文档页面上关于HTTP服务器的代码 网站上发布的代码为:Python 属性错误:模块';http.server';没有属性';ThreadingHTTPServer';,python,python-3.x,httpserver,Python,Python 3.x,Httpserver,我正在试用Python3文档页面上关于HTTP服务器的代码 网站上发布的代码为: def run(server_class=HTTPServer, handler_class=BaseHTTPRequestHandler): server_address = ('', 8000) httpd = server_class(server_address, handler_class) httpd.serve_forever() 此代码正在运行。我想尝试一下Threadin
def run(server_class=HTTPServer, handler_class=BaseHTTPRequestHandler):
server_address = ('', 8000)
httpd = server_class(server_address, handler_class)
httpd.serve_forever()
此代码正在运行。我想尝试一下ThreadingHTTPServer,如文档所示:
此类(ThreadingHTTPServer)与HTTPServer相同,但使用线程通过ThreadingMixIn处理请求。这对于处理web浏览器预打开套接字非常有用,HTTPServer将无限期地等待套接字
因此,我将上面的代码更改为:
def run(server_class=http.server.ThreadingHTTPServer, handler_class=http.server.BaseHTTPRequestHandler$
PORT = 8000
server_address = ('', PORT)
httpd = server_class(server_address, handler_class)
print("server running on port: ", PORT)
httpd.serve_forever()
但我得到以下错误:
Traceback (most recent call last):
File "simple_http_server.py", line 6, in <module>
def run(server_class=http.server.ThreadingHTTPServer, handler_class=http.server.BaseHTTPRequestHandler):
AttributeError: module 'http.server' has no attribute 'ThreadingHTTPServer'
回溯(最近一次呼叫最后一次):
文件“simple_http_server.py”,第6行,在
def run(server_class=http.server.ThreadingHTTPServer,handler_class=http.server.BaseHTTPRequestHandler):
AttributeError:模块“http.server”没有属性“ThreadingHTTPServer”
我想补充一点,我只是最近才使用Python,所以我可能错过了一些东西
你认为错误的原因是什么?我哪里做错了?我想我知道你为什么会有这个问题。如果你仔细阅读: 类http.server.ThreadingHTTPServer(服务器地址, RequestHandlerClass) 此类与HTTPServer相同,但使用线程通过ThreadingMixIn处理请求。这对于处理web应用程序非常有用 浏览器预先打开套接字,HTTPServer将在其上等待 无限期 在3.7版中新增。