在过去,我曾多次尝试在 CGI 或 WSGI 下运行 Python 脚本,结果却在我的网络服务器日志中出现以下不明确的错误:
[error] [client <client>] (2)No such file or directory: exec of '/path/to/web/root/test.py' failed
即使使用非常简单的脚本也会发生这种情况,即:
#!/usr/bin/python
print "Content-Type: text/html\n\n"
print "Hello, World!"
过去,我通过确保文件使用 unix 行结尾来设法解决问题,但出于好奇,我有以下问题:
- 据我所知,上述错误意味着无法找到 python 可执行文件;我是对的吗?
- 如果找不到 python 可执行文件,为什么? CRLF 结尾是否打破了 shebang 线?
- 除了转换格式之外,是否有解决此问题的方法?是否可以配置 CGI/WSGI 以自动处理此问题?
我已经在 Ubuntu 11.04 上使用 Apache 2.2 验证了这个特定示例,在 CGI 下运行 Python 2.6。
最佳答案
In the case that the python executable cannot be found, why? Does the CRLF endings break the shebang line?
是的,就是这样。
Is there a workaround for this other than converting the format? Is it possible to configure CGI/WSGI in such a way to handle this automatically?
有什么东西不会让你想吐?我不这么认为。
关于python - 如果文件具有 CRLF 行结尾,为什么在类 unix 系统上通过 CGI/WSGI 运行的 python 脚本会失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8389498/