我需要帮助如何运行脚本test.cgi,例如在apache中?我创建了测试脚本:
#!/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 80Python已正确安装。Test.cgi chmod为755
我是linux新手。它也会给我带来错误。在窗户上它给了我:
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!"知道吗?
发布于 2014-12-19 11:40:19
将这些添加到您的配置文件中:
<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!")对我起作用了。在Python3.x中,print是一个函数,因此必须传递字符串才能打印为一个论证。
https://stackoverflow.com/questions/27564253
复制相似问题