我需要帮助如何在apache中运行脚本test.cgi? 我创建了测试脚本:
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# enable debugging
import cgitb
cgitb.enable()
print "Content-Type: text/plain;charset=utf-8"
print
print "Hello World!
当我运行localhost/cgi-bin/test.cgi
它给了我错误。
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Apache/2.2.22 (Ubuntu) Server at localhost Port 80
Python安装正确。 Test.cgi chmod是755
我是linux新手。在wndows上它也给了我错误。 在Windows上它给了我:
End of script output before headers: python_test.cgi
我在windows上使用这个脚本:
#!"C:\Python34\python.exe"
# -*- coding: UTF-8 -*-
# enable debugging
import cgitb
cgitb.enable()
print "Content-Type: text/plain;charset=utf-8"
print
print "Hello World!"
有什么想法吗?
答案 0 :(得分:2)
将这些添加到配置文件中:
<Directory "/opt/lampp/htdocs/xampp/python">
Options +ExecCGI
AddHandler cgi-script .cgi .py
Order allow,deny
Allow from all
</Directory>
并将代码替换为:
import cgitb
cgitb.enable()
print ("Content-Type: text/plain;charset=utf-8")
print ()
print ("Hello World!")
它对我有用。在Python 3.x print
是一个函数,所以你必须传递要打印的字符串作为争论。