2014-12-19 98 views
0

我需要关于如何在apache中运行脚本test.cgi的帮助? 我创建的测试脚本:在apache上运行python脚本(linux和windows)

#!/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, [email protected] 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

你可以在你的'httpd.conf'文件中显示配置吗? – 2014-12-19 10:56:33

+0

在linux是空的,窗口是好的因为Perl脚本工作正常。 我添加了LoadModule cgi_module modules/mod_cgi.so和AddHandler cgi-script .cgi .pl .asp .py – Mirko 2014-12-19 11:37:40

回答

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是一个函数,所以你必须传递字符串作为一个参数来打印。

+0

在windows上? 我在Windows上使用xampp,而在linux上只使用apache。 – Mirko 2014-12-19 11:43:11

+0

是的,在xampp – 2014-12-19 11:44:01

+0

中会有一个'httpd.conf'文件,我知道,我之前编辑它以启用cgi_mod。我去了,但它没有奏效。 我使用python3.4它可以使这个错误? – Mirko 2014-12-19 11:47:46

相关问题