繁体   English   中英

尝试从flask应用程序创建.cgi应用程序时收到“ 500 Internal Server Error”

[英]“500 Internal Server Error” received when trying to create a .cgi application from a flask application

我使用以下代码在python中创建了以下Flask应用程序(名为simpleflask.py ):

from flask import Flask
import random

app = Flask(__name__)
app.secret_key = 'This is really unique and secret'

@app.route('/')
def index():
    a = random.randrange(2)
    if a == 1:
        return "<p>the random number selector returned 1</p>"
    else:
        return "<p>the random number selector returned 0</p>"

if __name__ == "__main__":
    app.run()

Flask应用程序可以在我的个人计算机上正常运行。

然后,我尝试使用Flask文档中提供的说明来创建.cgi应用程序,该文档具有以下代码:

from wsgiref.handlers import CGIHandler
from simpleflask import app

CGIHandler().run(app)

但是,它不能按预期方式工作。 我不断收到以下错误消息:

KeyError: 'SERVER_NAME'
Status: 500 Internal Server Error
Content-Type: text/plain
Content-Length: 59

A server error occurred.  Please contact the administrator.

我不太确定这是什么意思。 知道为什么我会收到此错误吗? 为了能够创建我的.cgi应用程序,我必须进行哪些更改? 任何和所有建议,欢迎。

您的cgi-script必须先编写标头。 至少是“内容类型”:

Content-Type: text/html;

之后是空行。 然后去你的内容。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM