gpt4 book ai didi

python - 服务器过载或 CGI 脚本中有错误

转载 作者:行者123 更新时间:2023-11-27 23:36:39 24 4
gpt4 key购买 nike

我是 CGI 的初学者,正在尝试将输入从 HTML 传递到 python(html 文件输入到 python 文件)。我不知道我哪里做错了。我正在关注 http://www.tutorialspoint.com/python/python_cgi_programming.htm 的教程为了获得额外帮助,我还查看了 Posting html form values to python script但失败了。我正在使用 Windows 8 操作系统。

这是我的代码:test.py

#!C:\Python27\python

# Import modules for CGI handling
import cgi, cgitb

# Create instance of FieldStorage
form = cgi.FieldStorage()

# Get data from fields
first_name = form.getvalue('first_name')
last_name = form.getvalue('last_name')

print "Content-type:text/html\r\n\r\n"
print "<html>"
print "<head>"
print "<title>Hello - Second CGI Program</title>"
print "</head>"
print "<body>"
print "<h2>Hello %s %s</h2>" % (first_name, last_name)
print "</body>"
print "</html>"

test.html

<html>
<body>
<form name="search" action="/cgi-bintest.py" method="get">
Search: <input type="text" name="searchbox">
<input type="submit" value="Submit">
</form>
</form>
</body>
</html>

在 chrome 上:当我写 "http://localhost/cgi-bin/test.html" 它给出:

Server error!

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there was an error in a CGI script.

If you think this is a server error, please contact the webmaster.

Error 500

localhost
Apache/2.4.16 (Win32) OpenSSL/1.0.1p PHP/5.6.12

注意:我将两个文件,即 test.py 和 test.html 都放在了“cgi-bin”中,对吗?因为我来自 php、javascript 等背景。

如果我做错了,请帮助吗?

最佳答案

您错误地配置了 apache 设置(并且您的 html 文件中有拼写错误)。将 HTML 文件放在您的文档根目录中(请参阅您的文档根设置),并将 CGI 文件放在 /cgi-bin/ 目录中。

然后在 chrome 中,转到 http://localhost/test.html

仅供引用——您的 HTML 文件中的拼写错误没有正确引用您的 cgi-bin。第 3 行缺少正斜杠。应该是:

<form name="search" action="/cgi-bin/test.py" method="get">

关于python - 服务器过载或 CGI 脚本中有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33593410/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com