gtk
gtk

Reputation: 101

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

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. What I am curious to find out is what the weird symbols mean (y\x03Ð.... and so on). 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? Is the data just in a format that the console cannot handle? What does it mean? You get the idea.

Upvotes: 9

Views: 18423

Answers (1)

blueteeth
blueteeth

Reputation: 3565

You're missing the ssl_context in app.run() which configures Flask to run with HTTPS support.

See the this article about it

If this is just for testing, you can use adhoc mode.

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

Upvotes: 6

Related Questions