CGIHTTPRequestHandler run php or python script in python

天涯浪子 提交于 2019-12-03 20:45:42

I think you are over engineering.

#!/usr/bin/env python
import CGIHTTPServer

def main():

    server_address = ('', 8000)
    handler = CGIHTTPServer.CGIHTTPRequestHandler
    handler.cgi_directories = ['/cgi']
    server = CGIHTTPServer.BaseHTTPServer.HTTPServer(server_address, handler)
    try:
        server.serve_forever()
    except KeyboardInterrupt:
        server.socket.close()

if __name__ == '__main__':
    main()
Brandon Runyon

Did you make the php file executable?? chmod +x spam.php (for Linux, I have no Idea how to make files executable on windows)

You would need the PHP interpreter installed on your PC as well

source from a reply HERE

You should also consider using THIS as an indirect alternative.

The problem is with the CGIHTTPServer Class. It doesn't set CGI env variables. This has been fixed here:
https://github.com/gabrielgrant/tonto/blob/master/tonto.py

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!