[英]Python flask error code 400, message Bad request version
The code of the website网站的代码
from flask import *
app = Flask(__name__)
@app.route("/<name>")
def user(name):
return f"Hello {name}!"
@app.route("/")
def home():
return render_template("index.html")
@app.route("/admin")
def admin():
return redirect(url_for("home"))
if __name__ == "__main__":
app.run()
If I go to http://127.0.0.1:5000/
there are not issues but when I go to https://127.0.0.1:5000/
(https not http this time) I get the following error If I go to http://127.0.0.1:5000/
there are not issues but when I go to https://127.0.0.1:5000/
(https not http this time) I get the following error
127.0.0.1 - - [17/Nov/2019 17:43:25] code 400, message Bad request version ('y\x03Ðã\x80¨R¾3\x8eܽ\x90Ïñ\x95®¢Ò\x97\x90<Ù¦\x00$\x13\x01\x13\x03\x13\x02À+À/̨̩À,À0À')
The error code 400, message Bad request version
is basically what I expected since I have not set up SSL nor have I declared what the website should do when getting a https request.错误code 400, message Bad request version
基本上是我所期望的,因为我没有设置 SSL 也没有声明网站在收到 https 请求时应该做什么。 What I am curious to find out is what the weird symbols mean (y\x03Ð.... and so on).我很想知道奇怪符号的含义(y\x03Ð....等等)。 This goes out to multiple questions such as: Where do they come from?这涉及多个问题,例如:它们来自哪里? Have the python code attempted to access a random memory location with no specific data? python 代码是否尝试访问没有特定数据的随机 memory 位置? Is the data just in a format that the console cannot handle?数据是否只是控制台无法处理的格式? What does it mean?这是什么意思? You get the idea.你明白了。
You're missing the ssl_context
in app.run()
which configures Flask to run with HTTPS support.您缺少ssl_context
app.run()
中的 ssl_context ,它将 Flask 配置为在 HTTPS 支持下运行。
See the this article about it请参阅有关它的这篇文章
If this is just for testing, you can use adhoc
mode.如果这只是为了测试,您可以使用adhoc
模式。
if __name__ == "__main__":
app.run(ssl_context="adhoc")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.