Python CGI错误500:脚本标头过早结束 [英] Python CGI Error 500: Premature end of script headers

查看:66
本文介绍了Python CGI错误500:脚本标头过早结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相当复杂的python脚本,我试图运行该脚本,该脚本会导入其他自写模块和诸如sqlite之类的东西。当我去运行脚本时,出现500:服务器内部错误,日志显示:脚本头过早结束。

I have this fairly complex python script im trying to run which imports other self-written modules and things like sqlite. When I go to run the script, I get a 500: internal server error and the log says: Premature end of script headers.

我知道这意味着我可能不知道

I know this means that I probably don't have my header correctly placed/typed but I believe I do.

#!/usr/bin/env python

import cgi
import cgitb; cgitb.enable(logdir=..., format="text")

print "Content-type: text/html"
print

看起来不错吧?

我继续执行脚本并在最后打印结果。所有其他模块都没有标题或哈希表,但是我认为这很好。

I continue with the script and print the results at the end. All the other modules don't have the header or the hashbang, but I think that's fine.

可能是什么问题?

推荐答案

我遇到了同样的问题。这样解决了它:

I had same problem. This solved it:

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

.
.
.

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

这篇关于Python CGI错误500:脚本标头过早结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆