2011-07-07 175 views
6

我想在浏览器中运行python文件。 我已经安装了apache。并配置了httd.conf文件。 我已经创建了test.py文件。 然后我尝试用我的浏览器运行test.py,方法是输入htt://localhost/test.py。当我这样做,我得到以下错误:在浏览器中运行.py文件

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. 

在我的错误日志

[Thu Jul 07 18:39:55 2011] [error] [client 127.0.0.1] (OS 2)The system cannot find the file specified. : couldn't create child process: 720002: test.py 
[Thu Jul 07 18:39:55 2011] [error] [client 127.0.0.1] (OS 2)The system cannot find the file specified. : couldn't spawn child process: C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/test.py 

可以在这里是什么问题?

+7

运行的Python浏览器意味着你必须配置你的浏览器,而不是你的服务器。当您在浏览器中运行Python时,您的浏览器(FireFox,IE,Opera,Safari等)正在运行Python。这与Apache无关。你真的**想做什么? –

+0

@ S.Lott如何配置浏览器? –

回答

0

如果你还没有这样做了,你需要在test.py适当的权限设置为755

+0

感谢您的回复,我如何在Windows 7中设置此权限。 –

+0

@Roayl Pinto - 好问题;我自己是一个Unix人。我没有意识到你在Windows上,这对Apache来说可能没有关系。 –

1

如果它是一个CGI程序,确保它符合CGI规范(即输出一个标题行在尝试写入任何其他文件之前使用MIME类型和空白行)

0

C:/ Program Files(x86)/ Apache Software Foundation/Apache2.2/htdocs /中的文件是错误消息状态。如果不是,你需要把它放在那里或者改变你的配置,使它看起来在正确的位置。

此外,作为其他答案,检查它是否具有正确的权限,并检查它是否输出所有必要的标题。

0

我想您的网址更改为更可能一个在一审,即http://localhost/test.py而不是你报的一个(htt://localhost/test.py

0

你可以尝试mod_python的,它支持用python.the分析器Web应用程序获得作为apache模块嵌入到服务器中,因此应用运行速度比传统cgi快。 此外,如果你想坚持cgi的方式,确认所有的.py文件都在名为“cgi-bin”的文件夹中并且具有可执行权限。下的htdocs

2

选项+ ExecCgi, 的ScriptAlias/cgi-bin目录/ “C:/ Program Files文件/阿帕奇软件基金会/ APACHE2.2/cgi-bin目录/”

这就是我已经和它的作品

+0

你的文件可能应该在cgi-bin下 –

10

如果你的shebang不正确(例如,一个像#!/usr/bin/env python这样的Unix),也可能发生这种情况。如果是这样的情况下,将其更改为正确的路径到你的Python可执行文件(例如:#!C:\Python26\python.exe),或者看看这个答案: How do I ignore the Perl shebang on Windows with Apache 2?