python - 如果文件具有 CRLF 行结尾,为什么在类 unix 系统上通过 CGI/WSGI 运行的 python 脚本会失败?

标签 python linux cgi webserver wsgi

在过去,我曾多次尝试在 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 行结尾来设法解决问题,但出于好奇,我有以下问题:

  1. 据我所知,上述错误意味着无法找到 python 可执行文件;我是对的吗?
  2. 如果找不到 python 可执行文件,为什么? CRLF 结尾是否打破了 shebang 线?
  3. 除了转换格式之外,是否有解决此问题的方法?是否可以配置 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/

相关文章:

python - Tensorflow:给定真实索引创建 bool 矩阵

python - 在 Python 中以对数方式缩放二维数组

python - 如何在 AWS Glue pyspark 脚本中合并两个节点

java - 如何在Serenity bdd中手动使步骤失败而不跳过其他步骤

python - 尝试切换到Python,遇到问题

perl - 如何设置 Perl 的 CGI 脚本模块包含路径?

python - 保持套接字在线程中打开,并从Main发送命令

c - 如何从 C 文件更改终端中的目录

使用 GNU 工具链 (gcc/ld) 从静态库创建共享库

Apache CGI 超时 - 它如何杀死和/或通知 child ?