每当我通过提交表单调用下面的cgi脚本时,都会收到一个内部服务器错误,服务器日志显示以下行: 脚本头过早结束:LoopFinderRetrieval.cgi,引用者:http://loopfinder-prod-01.uit.tufts.edu/LoopFinderRetrieval.html
简而言之,cgi文件意味着进入由提交时给定的运行ID指示的文件夹,打开并读取一个名为作业状态.txt,然后根据结果执行操作。这可以是向用户返回特定的错误,也可以是向用户提供结果。据我所知,如果我忽略了以下行,就会导致我看到的错误:
"Content-type:text/html\r\n\r\n"
但是这行代码是存在的,在同一台服务器上使用完全相同的PrintHeader()和PrintFooter()函数的另一个CGI脚本正在正常运行。有人能看到任何可能导致这种情况的明显错误吗?如果没有,我所读到的可能是权限问题。如果是那样的话,我就得联系管理员,把它修好,但我不想这样做,除非我知道是问题所在。谢谢。在
^{pr2}$
好的,我们发现这里有代码错误,而不是权限错误。 事实上很尴尬。更正后的代码如下。第一个问题是我使用
file.read()
逐行读取文件。我应该使用file.readlines()
,并将该行另外改为[line.rstrip('\n') for line in pre_textfile]
,以便删除换行符。第33行还有一个索引错误,我已经更正了。现在还不清楚的是,为什么我不能让任何类型的伐木为我工作,这样可以为几个人节省相当多的时间。在啊!/usr/垃圾箱/Python2.6
错误消息足够模糊,但它基本上意味着输出在头结束之前结束。就像你说的。在
如果你的脚本崩溃了怎么办。那么就不会打印页眉了,我猜可能会发生这种错误。在
在脚本中添加一些logging,以便更好地了解实际发生的情况。例如,您可以将整个脚本包装在
try
块中,并记录任何异常。在如果你有一点代码需要重复的话,你可能会更容易地发现你的代码。在我看来,页眉和页脚总是打印出来的,例如,也许只能打印一次。在
我的猜测是,当你的文件太短时,脚本会崩溃。当您命中一行上有
textfile[1] == something
并且文件只有一行时,您将得到以下异常:但这只是猜测,适当的日志记录会让你知道。在
编辑:
我看到您正在使用^{} 。也许可以使用这个模块中的日志记录。尝试禁用浏览器输出并将任何异常发送到日志文件。将
^{pr2}$cgitb.enable()
改为:如果使用
cgitb
,则不需要将程序包装在try
块中,实际上这两个方法可能会相互干扰。在相关问题 更多 >
编程相关推荐