【问题标题】:CGI Script Internal Server Error WindowsCGI 脚本内部服务器错误窗口
【发布时间】:2014-05-18 07:05:42
【问题描述】:

我是 CGI 脚本的新手。我已经在 Windows 上安装了 Wamp Server,并在路径 D:\Installation\Python33 安装了 Python。

我已将 CGI 脚本 (test.cgi) 编写为:

print "Content-Type: text/html"
print
print "<html><head><title>Books</title></head>"
print "<body><h1>Books</h1>These are the books</body></html>"

我将它保存在 C:\wamp\www\ 目录下。 当我从浏览器运行它时,它给了我错误“内部服务器错误

服务器遇到内部错误或配置错误,无法完成您的请求。”

我检查了 apache_error.log 显示:

[Sun May 18 12:30:13 2014] [error] [client 127.0.0.1] (OS 3)The system cannot find the path specified.  : couldn't create child process: 720003: test.cgi
[Sun May 18 12:30:13 2014] [error] [client 127.0.0.1] (OS 3)The system cannot find the path specified.  : couldn't spawn child process: C:/wamp/www/test.cgi

我觉得这里需要设置Python Path。

我在这里发现了类似的问题:

internal server error (500) in simple cgi script

但找不到如何在 windows 上设置 python 路径。请帮忙。

提前致谢。

【问题讨论】:

    标签: python cgi


    【解决方案1】:

    终于找到解决办法了:

    我修改了第一行以设置 python 路径,然后使用 sys 模块将输出写为:

    #!d:/Installations/Python33/python.exe
    
    import sys
    sys.stdout.write("Content-type: text/html\r\n\r\n")
    sys.stdout.write("<html><head><title>Books</title></head>")
    sys.stdout.write("<body><h1>Books</h1>These are the books</body></html>")
    

    成功了!!!

    【讨论】:

    • 它可以工作,但为什么简单的 print("hello world") 不能在这里工作
    【解决方案2】:

    将您的脚本放在C:\wamp\bin\apache\apache2.2.22\cgi-bin
    (如果您没有 cgi-bin 文件夹,则创建一个)

    然后在 "httpd.conf" 中启用 cgi

    即找到&lt;DIRECTORY /&gt; 并用这个替换它(在你的httpd.conf 文件中)

    <Directory />
    Options FollowSymLinks +ExecCGI
    AllowOverride None
    Order deny,allow
    Allow from all
    </Directory>
    

    对于 Windows(在本地主机上)

    #!D:\Installation\Python33
    print("Content-Type: text/html")
    print()
    print("<html><head><title>Books</title></head>")
    print("<body><h1>Books</h1>These are the books</body></html>")
    

    然后像这样调用你的脚本

    http://localhost/cgi-bin/yourfilename
    

    【讨论】:

    • @vijay 您正在使用 python33。所以打印功能如下 print("your content") 而不是 print "your content"
    【解决方案3】:

    在 test.py 中使用此代码

    #!python
    
    print ("Content-type: text/html\n")
    print ("python test ok\r\n<br/>")
    #print (help)
    help (os.chmod())
    

    并将 D:\Installation\Python33 放入路径变量中

    重启apache

    注意:Wamp Server 必须安装在 D 盘。

    我希望这会奏效

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-30
      • 1970-01-01
      • 2011-10-09
      • 2013-11-13
      • 2016-04-24
      • 2014-09-12
      • 2018-12-10
      • 2016-12-22
      相关资源
      最近更新 更多