运行 Python - 500 内部服务错误

Running Python - 500 Internal Service Error

我有以下代码 (test.cgi):

#!/usr/bin/env python
# -*- coding: UTF-8 -*-

# enable debugging
import cgitb
cgitb.enable()

print "Content-Type: text/plain;charset=utf-8"
print

print "Hello World!"

文件是 CHMOD 777,它所在的目录也是。

我收到以下错误日志

[Sun Apr 12 02:24:46.395628 2015] [cgi:error] [pid 3574:tid 34479148032] [client 172.17.240.2:19716] AH01215: env: python\r: : /fs5a/cheerupper/public/scripts/test.cgi
[Sun Apr 12 02:24:46.396715 2015] [cgi:error] [pid 3574:tid 34479148032] [client 172.17.240.2:19716] AH01215: No such file or directory: /fs5a/cheerupper/public/scripts/test.cgi
[Sun Apr 12 02:24:46.397453 2015] [cgi:error] [pid 3574:tid 34479148032] [client 172.17.240.2:19716] End of script output before headers: test.cgi

当我尝试在浏览器中 运行 时收到 500 内部服务错误。当通过命令行 SSH 连接到服务器时,我可以 运行。我在 Namecheap 服务器上试过,现在正在尝试 NearlyFreeSpeech.net 得到相同的结果。

您的文件似乎保存了 Windows 个换行符。您的编辑器应该可以选择将其更改为您的服务器所期望的 Unix 换行符。

简短的 CGI 程序:

#!/usr/bin/env python
# -*- coding: UTF-8 -*-

# enable debugging
import cgitb
cgitb.enable()

print "Content-Type: text/plain;charset=utf-8"
print

print "Hello World!"