【问题标题】:Python Premature end of script headers errorPython脚本头错误的过早结束
【发布时间】:2012-12-03 00:25:15
【问题描述】:

我正在运行一个新的 python 脚本,经过多次试验,我已经让它运行了(有点)。这是文件:

#!/usr/bin/python
import cgi
import cgitb

print "Content-type: text/html"
print

print "this is working"

它在 SSH 中运行良好,但在浏览器中我收到 500 错误。查阅错误日志,我得到“脚本头过早结束”。我正在使用 mod_wsgi 运行 Ubuntu,并且我相信我已经正确设置了 apache2.conf,站点可用/默认设置正确,并且我拥有适当的权限并且没有正确设置。而且,就像我说的,python 在 SSH 中运行良好 - 但我需要它作为 Web 应用程序运行。

任何人有什么想法吗?我已经为此工作了两天,但没有任何工作。

【问题讨论】:

  • content-type 声明后添加两个换行符。
  • 您为什么将mod_wsgi 用于CGI 应用程序?您要么需要在脚本中使用 WSGI,要么配置 Apache 以将其作为 CGI 脚本运行。 httpd.apache.org/docs/2.2/howto/cgi.html

标签: python apache ubuntu cgi wsgi


【解决方案1】:

如果这是通过 mod_wsgi 编写的 wsgi 脚本,它应该看起来像这样:

def application (env, r):
    body = 'this is working'
    status = '200 OK'
    response_headers = [ ('Content-Type', 'text/html'), ('Content-Length', str (len (body) ) ) ]
    r (status, response_headers)
    return [body]

【讨论】:

    【解决方案2】:

    感谢大家的帮助。通过上面的 Liquid_Fire 链接(http://httpd.apache.org/docs/2.2/howto/cgi.html),我发现了一些关于 suexec 运行的信息。我检查了一下,我的盒子正在运行 suexec。我评论了它,万岁!它有效!

    【讨论】:

      猜你喜欢
      • 2012-06-09
      • 2014-06-03
      • 2017-07-22
      • 2013-07-09
      • 1970-01-01
      • 1970-01-01
      • 2011-05-28
      • 1970-01-01
      相关资源
      最近更新 更多