脚本头的过早结束python cgi脚本中的错误

MrC*_*tro 6 python apache cgi

我遇到了一个问题,我最近搬到了一个vps.我正在尝试运行python cgi脚本,但我得到一个apache脚本标头的过早结束错误.

(我chmod + x脚本文件)

该脚本非常简单:

#!/usr/bin/env python                                      
import cgi, cgitb
cgitb.enable()

print "Content-type: text/html"
print "<html><body>hello scritp</body></html>"
Run Code Online (Sandbox Code Playgroud)

现在如果我将脚本命名为test**.py**它在服务器上运行良好.但是,如果我以正确的方式执行,请将其称为测试**.cgi**我收到内部服务器错误.

我从终端运行脚本

./test.cgi
Run Code Online (Sandbox Code Playgroud)

我没有错

 Content-type: text/html
 <html><body>hello scritp</body></html>
Run Code Online (Sandbox Code Playgroud)

有没有人遇到过这个问题?并为它的解决方案?:)干杯

use*_*424 8

将标题更改为:

print "Content-type: text/html\n\n"
Run Code Online (Sandbox Code Playgroud)