使用,您处在正确的位置
CGIHTTPRequestHandler,因为
.htaccess文件对内置的http服务器没有任何意义。有一个
CGIHTTPRequestHandler.cgi_directories变量,用于指定将可执行文件视为cgi脚本的目录(这里是检查本身)。你应该考虑移动
test.py到一个
cgi-bin或
htbin目录,并使用下面的脚本:
cgiserver.py:
#!/usr/bin/env python3from http.server import CGIHTTPRequestHandler, HTTPServerhandler = CGIHTTPRequestHandlerhandler.cgi_directories = ['/cgi-bin', '/htbin'] # this is the defaultserver = HTTPServer(('localhost', 8123), handler)server.serve_forever()cgi-bin / test.py:
#!/usr/bin/env python3print('Content-type: text/htmln')print('<title>Hello World</title>')您应该最终得到:
|- cgiserver.py|- cgi-bin/ ` test.py
与运行
python3 cgiserver.py并向发送请求
localhost:8123/cgi-bin/test.py。干杯。



