【问题标题】:Premature end of script headers Error in python cgi scriptpython cgi脚本中的脚本头过早结束错误
【发布时间】:2014-06-03 22:10:33
【问题描述】:

我遇到了一个我最近搬到的 vps 的问题。我正在尝试运行 python cgi 脚本,但我得到一个 apache Premature end of script headers 错误。

(我 chmod +x 脚本文件)

脚本很简单:

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

print "Content-type: text/html"
print "<html><body>hello scritp</body></html>"

现在,如果我将脚本命名为 test**.py**,它在服务器上运行良好。但如果我以正确的方式进行操作,调用它 test**.cgi** 我会收到内部服务器错误。

我从终端运行脚本

./test.cgi

我没有错误

 Content-type: text/html
 <html><body>hello scritp</body></html>

在此问题之前有人遇到过吗?以及解决方案? :) 干杯

【问题讨论】:

    标签: python apache cgi


    【解决方案1】:

    将标题更改为:

    print "Content-type: text/html\n\n"
    

    【讨论】:

      【解决方案2】:

      HTTP 标头和正文之间必须至少有一个空行。 所以

      print "Content-type: text/html\n" 可以正常工作

      参考:Wikipedia

      【讨论】:

        猜你喜欢
        • 2012-06-09
        • 2012-06-25
        • 2012-04-07
        • 2012-12-03
        • 2021-12-03
        • 2011-03-19
        • 2011-02-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多