Python 2.7.8标题之前的脚本输出结束:te.py

时间:2015-12-13 17:35:38

标签: python ubuntu-12.04 cgi-bin

我正在使用Ubuntu 12.04使用Vmware并使用Python cgi-bin。我正在学习本教程:http://archive09.linux.com/feature/136602。我的example1.py "Hello, Linux.com!"打印成功,但是example2.py不是,服务器经常说:

Server error!

The server encountered an internal error and was unable to complete your request.

Error message:
End of script output before headers: te.py

If you think this is a server error, please contact the webmaster.
Error 500
localhost
Apache/2.4.16 (Unix) OpenSSL/1.0.1p PHP/5.6.12 mod_perl/2.0.8-dev Perl/v5.16.3 

代码是:

#!/usr/bin/python
import cgi
print "Content-type: text/html"
print
form = cgi.FieldStorage()
laptops = form.getvalue('laptops','0')
desktops = form.getvalue('desktops','0')
print """
<html>
<body>
<form action='second.py'>
How many laptops do you own?&nbsp;
<input type='radio' checked name='laptops' value='0' />0&nbsp;
<input type='radio' name='laptops' value='1' />1&nbsp;
<input type='radio' name='laptops' value='2' />2
<p>
How many desktops do you own?&nbsp;
<input type='radio' checked name='desktops' value='0' />0&nbsp;
<input type='radio' name='desktops' value='1' />1&nbsp;
<input type='radio' name='desktops' value='2' />2
<p>
<input type='submit' />
<p>
You own %d computers.
</form>
</body>
</html>""" % (int(laptops)+int(desktops))

我自己失败了,无法弄清楚原因。请帮助

1 个答案:

答案 0 :(得分:0)

看起来你提供了python路径,你能检查一下你是否提供了文件的执行权限吗?我想添加执行权限将解决您的错误。

相关问题