我正在运行一个新的 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 应用程序运行。
任何人的任何想法吗?我已经为此工作了两天,但没有任何工作。
最佳答案
如果这是通过 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]
关于Python脚本头错误的过早结束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13888217/