在apache(linux和windows)上运行python脚本

在apache(linux和windows)上运行python脚本,python,linux,windows,apache,Python,Linux,Windows,Apache,我需要关于如何在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 这给了我错误

我需要关于如何在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!"

有什么想法吗?

将这些添加到配置文件中:

  <Directory "/opt/lampp/htdocs/xampp/python">
      Options +ExecCGI
      AddHandler cgi-script .cgi .py
      Order allow,deny
      Allow from all
  </Directory>

这对我有用。在Python3.x中,
print
是一个函数,因此必须将要打印的字符串作为参数传递。

能否在
httpd.conf
文件中显示配置?在linux中是空的,windows是可以的,因为perl脚本工作正常。我在windows上添加了LoadModule cgi_module modules/mod_cgi.so和AddHandler cgi script.cgi.pl.asp.py?我在windows上使用xampp,在linux上只使用apache。是的,xamppI中会有一个
httpd.conf
文件。我知道,我以前编辑过它以启用cgi_mod。我试过了,但没用。我使用的是python3.4,它会犯这个错误吗?
import cgitb
cgitb.enable()

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

print ("Hello World!")