OS X上的Python CGIHTTPServer访问被拒绝

5 permissions python-2.7 osx-mountain-lion 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).

小智 10

终于搞定了.这是基本脚本;

index.py

#!/usr/bin/env python
import cgi
print 'Content-Type: text/html\n\n'
print ''
print 'test'
Run Code Online (Sandbox Code Playgroud)

要求

  • 该文件需要是可执行的; $ chmod +x index.py
  • 该文件需要 #!/usr/bin/env python

希望它可能在将来帮助某人.