标签: cgihttpserver

Python CGIHTTPServer 默认目录

我有以下用于 CGI 处理 HTTP 服务器的最小代码,这些代码源自内管上的几个示例:

#!/usr/bin/env python

import BaseHTTPServer
import CGIHTTPServer
import cgitb;

cgitb.enable()  # Error reporting

server = BaseHTTPServer.HTTPServer
handler = CGIHTTPServer.CGIHTTPRequestHandler
server_address = ("", 8000)
handler.cgi_directories = [""]

httpd = server(server_address, handler)
httpd.serve_forever()
Run Code Online (Sandbox Code Playgroud)

然而,当我执行脚本并尝试使用 CGI 在同一目录中运行测试脚本时http://localhost:8000/test.py,我看到的是脚本的文本,而不是执行的结果。

权限都设置正确,测试脚本本身不是问题(因为python -m CGIHTTPServer当脚本驻留在 cgi-bin 中时,我可以使用 运行它)。我怀疑这个问题与默认的 CGI 目录有关。

我怎样才能让脚本执行?

python cgi httpserver cgihttprequesthandler cgihttpserver

6
推荐指数
1
解决办法
7284
查看次数

OS X上的Python CGIHTTPServer访问被拒绝

尝试从浏览器中触发CGI内的Python脚本时出现此错误;

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/CGIHTTPServer.py", line 251, in run_cgi
    os.execve(scriptfile, args, env)
OSError: [Errno 13] Permission denied
1.0.0.127.in-addr.arpa - - [20/Apr/2013 14:51:16] CGI script exit status 0x7f00
Run Code Online (Sandbox Code Playgroud)

我没有以root($ python-32 main.py)身份运行主进程.

这个主题似乎对我不起作用.

使脚本可执行也不起作用($ chmod +x index.py,-rwxr-xr-x).

permissions python-2.7 osx-mountain-lion cgihttpserver

5
推荐指数
1
解决办法
4939
查看次数