Python CGI Error 500: Premature end of script headers

独自空忆成欢 提交于 2019-12-06 12:26:20

问题


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

Looks right, right?

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.

What could the problem be?


回答1:


I had same problem. This solved it:

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

.
.
.

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


来源:https://stackoverflow.com/questions/10901662/python-cgi-error-500-premature-end-of-script-headers

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!