![](/img/trans.png)
[英]Getting a 500 Internal server error on my flask application, does not kill process running on a particular port when application is stopped
[英]“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.