您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何在由python创建的BaseHTTPSERVER上执行python脚本?

如何在由python创建的BaseHTTPSERVER上执行python脚本?

使用,您处在正确的位置CGIHTTPRequestHandler,因为.htaccess文件对内置的http服务器没有任何意义。有一个CGIHTTPRequestHandler.cgi_directories变量,用于指定将可执行文件视为cgi脚本的目录(这里是检查本身)。你应该考虑移动test.py一个cgi- binhtbin目录,并使用下面的脚本:

#!/usr/bin/env python3

from http.server import CGIHTTPRequestHandler, HTTPServer

handler = CGIHTTPRequestHandler
handler.cgi_directories = ['/cgi-bin', '/htbin']  # this is the default
server = HTTPServer(('localhost', 8123), handler)
server.serve_forever()

#!/usr/bin/env python3
print('Content-type: text/html\n')
print('<title>Hello World</title>')

您应该最终得到:

|- cgiserver.py
|- cgi-bin/
   ` test.py

与运行python3 cgiserver.py并向发送请求localhost:8123/cgi-bin/test.py。干杯。

python 2022/1/1 18:43:57 有505人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶