You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python CGI脚本仅在本地内置服务器正常运行,部署到大学服务器出现500错误的紧急求助

Python CGI脚本仅在本地内置服务器正常运行,部署到大学服务器出现500错误的紧急求助

各位大佬救命!我的项目今天下午3点就要交了,现在遇到了致命问题😭

我用HTML和Python CGI做了一个计算复活节日期的网站,在本地用Python内置服务器跑python3 -m http.server --cgi -b 127.0.0.1 8000完全正常,所有功能都能正常工作。但部署到学校的服务器上后,一旦提交表单触发CGI脚本,就直接弹出500错误:

Error
Referred from: [大学项目路径]
HTTP status: 500

Your code returned an error:
End of script output before headers: hello_get.py

我完全搞不懂这个错误到底是什么意思,为什么本地好好的,到学校服务器就不行了?求大家帮忙看看问题出在哪!

以下是我的代码:

HTML代码

<!DOCTYPE html>
<html>

<head>
<link rel="stylesheet" href="style.css">
<meta charset="utf-8">
<title>First Form</title>
</head>
<h3>Would you like it outputted numerically or Verbosely</h3>
<body>
<form class = "border" action="cgi-bin/hello_get.py" method="POST">
<input type="radio" name="Output" id="num" value="num"/> numerically <br />
<input type="radio" name="Output" id="verb" value="verb"/> Verbosely <br>
<input type="radio" name="Output" id="both" value="both"/> Both <br>
<label for="num_alph">choose the option you'd prefer</label>

<h3>Enter a Year to find out when the easter of that year is</h3>
<label for="theYear">Enter the year of the easter date you would like to know</label>
<input type="number" id="theYear"
name="theYear" size="10"/> <br/>
<input type="submit" value="submit"/>
</form>

</body>
</html>

Python CGI脚本代码

import cgi, cgitb
cgitb.enable()
form = cgi.FieldStorage()
# Numerical = form.getvalue('num')
# Verbose = form.getvalue('verb')
# both = form.getvalue('both')
choice = form.getvalue('Output')
year = form.getvalue('theYear')
year = int(year)
NoApril = False
verbose = ['first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth', 'tenth', 'eleventh', 'twelfth', 'thirteenth', 'fourteenth', 'fifteenth', 'sixteenth', 'seventeenth', 'eighteenth', 'nineteenth', 'twentieth', 'twenty-first', 'twenty-second', 'twenty-third', 'twenty-fourth', 'twenty-fifth', 'twenty-sixth', 'twenty-seventh', 'twenty-eighth', 'twenty-ninth', 'thirtieth']
a = year % 19
b = year % 4
c = year % 7
d = year // 100
e = (13+d*8) // 25
f = d // 4
g = (15 - e + d - f) % 30
h = (4 + d - f) % 7
i = (a*19 + g) % 30
j = (b*2 + c*4 + 6*i + h) % 7
Easter = i + j - 9 
March = 22 + i + j
if Easter <= 0:
    NoApril = True
else:
    if i == 28 and j == 6 and (g*11 + 11) % 30 < 19 and Easter == 25:
        Easter = 18
    elif i == 29 and j == 6 and Easter==26:
        Easter = 19
print('Content-Type: text/html; charset=utf-8')
print('')
print('<!DOCTYPE html>')
print('<html>')
print('<head>')
print('<title>find out the date of eatser on a given year</title>')
print('<link rel="stylesheet" href="/style.css">')
print("<style>")
print("  .body {")
print("    width: 300px;")
print("    padding: 20px;")
print("    margin: 20px;")
print("    border: 1px solid #ccc;")
print("    border-radius: 5px;")
print("    text-align: center;")
print("</style>")
print('</head>')
print('<body>')
print('<p class="body">')
if NoApril:
    VerbMarch = verbose[March-1]
else:
    VerbEaster = verbose[Easter - 1]
if choice == "num":
    if NoApril:
        if March < 10:
            print("In the year " + str(year) + " easter falls on " + "0" + str(March) + "/03/" + str(year) + "<br/>")
        else:
            print("In the year " + str(year) + " easter falls on " + str(March) + "/03/" + str(year) + "<br/>")
    else:
        if Easter<10:
            print("In the year " + str(year) + " easter falls on " + "0" + str(Easter) + "/04/" + str(year) + "<br/>")
        else:
            print("In the year " + str(year) + " easter falls on " + str(Easter) + "/04/" + str(year) + "<br/>")
elif choice == "verb":
    if NoApril:
        print("In the year " + str(year) + " easter falls on the " + VerbMarch + " of March " + str(year) + "<br/>")
    else:
        print("In the year " + str(year) + " easter falls on the " + VerbEaster + " of April " + str(year) + "<br/>")
elif choice == "both":
    if NoApril:
        if March < 10:
            print("In the year " + str(year) + " easter falls on " + "0" + str(March) + "/03/" + str(year) + "<br/>")
        else:
            print("In the year " + str(year) + " easter falls on " + str(March) + "/03/" + str(year) + "<br/>")
    else:
        if Easter<10:
            print("In the year " + str(year) + " easter falls on " + "0" + str(Easter) + "/04/" + str(year) + "<br/>")
        else:
            print("In the year " + str(year) + " easter falls on " + str(Easter) + "/04/" + str(year) + "<br/>")
    if NoApril:
        print("In the year " + str(year) + " easter falls on the " + VerbMarch + " of March " + str(year) + "<br/>")
    else:
        print("In the year " + str(year) + " easter falls on the " + VerbEaster + " of April " + str(year) + "<br/>")
print('</p>')
print('</body>')
print('</html>')

我还有配套的CSS,但应该和这个错误无关就不贴了。真的非常急,希望能尽快得到大家的帮助!

备注:内容来源于stack exchange,提问作者abxty

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 16:30:27