我有下面这个简单的python脚本hellocgi.py
import sys
sys.stdout.write("Content-type: text/html \r\n\r\n")
sys.stdout.write("<!doctype html><html><head><title>Hello CGI</title></head>")
sys.stdout.write("<body><Hello CGI</h2></body></html>")该文件被放置在目录中
/Users/MyName/cgi-bin然后我更改权限
chmod +x hellocgi.py然后运行
python -m CGIHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...如果我用http://localhost:8000/cgi-bin/hellocgi.py,打开浏览器,我会得到:
Error response
Error code 404.
Message: No such CGI script ('/cgi-bin/hellocgi.py').
Error code explanation: 404 = Nothing matches the given URI.有人能告诉我发生了什么事吗?我还尝试在/Library/WebServer/CGI-Executables中调整脚本的步调,但这不起作用。
谢谢
发布于 2013-09-15 08:35:44
脚本需要读取权限,而不是执行权限。python解释器执行,脚本只是从文件系统中读取。
发布于 2013-09-16 07:34:42
我用无效的(不存在的)路径重现了您列出的错误,因此我建议您重新检查您正在使用的目录以及文件名和urls的拼写。
根据文档1,“这个类用于提供当前目录及以下目录中的文件或CGI脚本的输出”,CGIHTTPServer使用以其运行目录为根的目录树。因此,您应该选择某个目录($HOME可以工作,如果您只想执行一些测试,则/tmp/www/也可以),设置您想要提供的文件,并从该目录启动服务器。
1
https://stackoverflow.com/questions/18807757
复制相似问题