How to host python cgi script with `python -m SimpleHTTPServer 8000` or `python -m CGIHTTPServer 8000`?

混江龙づ霸主 提交于 2019-11-28 08:12:17

Try with python -m CGIHTTPServer 8000.

Note that you have to move the script to a cgi-bin or htbin directory in order to be runnable.

SO doesn't allow me to comment so I'm adding this as a separate answer, addition to rodrigo's.

You can use another parameter cgi_directories which defaults to ['/cgi-bin', '/htbin']. More info here

When I ran into this issue I found that depending on which directory you are in when you run the python -m CGIHTTPServer 8000 command yields different results. When attempting to run the command while in the cgi-bin directory the browser continued to return the raw script code. once I cd'ed one level higher and ran the python -m CGIHTTPServer 8000 command again my script began executing.

@Bentley4 -ifyou are still not able to do, try importing cgi.

#!C:\Python34\python.exe -u import cgi print ("Content-type:text/html")

HTH

in Python3 the command line is simply

python -http.server --cgi 8000

This work for me, run the python -m CGIHTTPServer 8000 command same menu level with cgi-bin,and move cgi_script.py into cgi-bin folder.In browser type http://localhost:8000/cgi-bin/cgi_script.py

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