pallets / flask

The Python micro framework for building web applications.
https://flask.palletsprojects.com
BSD 3-Clause "New" or "Revised" License
68.08k stars 16.22k forks source link

Very strange error #4599

Closed OgreTransporter closed 2 years ago

OgreTransporter commented 2 years ago

Environment:

I have tried the following program:

from flask import Flask
import os

app = Flask(__name__)

@app.route('/')
def hello():
    """Renders a sample page."""
    return "Hello World"

if __name__ == '__main__':
    HOST = os.environ.get('SERVER_HOST', '0.0.0.0')
    try:
        PORT = int(os.environ.get('SERVER_PORT', '5002'))
    except ValueError:
        PORT = 5002
    app.run(HOST, PORT, False)

When I now open http://testserver:5002/ in the browser I get the following log:

134.91.90.144 - - [19/May/2022 11:48:15] code 400, message Bad request version ('testserver\x00\x17\x00\x00ÿ\x01\x00\x01\x00\x00')
testserverÿ" HTTPStatus.BAD_REQUEST -üÈ@|øÞR"ÒqD¦3 cGß]°1Æ»ø)Û{ÌK-²N$m-°{NãÅDl¢ À+À/À,À0̨̩ÀÀzz
134.91.90.144 - - [19/May/2022 11:48:15] code 400, message Bad request version ('testserver\x00\x17\x00\x00ÿ\x01\x00\x01\x00\x00')
134.91.90.144 - - [19/May/2022 11:48:15] "üÉóF
testserverÿ" HTTPStatus.BAD_REQUEST -            :Ë5Óö¦V°îøàÜì&1 êu½2Êm9VKý~>P*Ó='µ

This looks like the encoding is not working.

davidism commented 2 years ago

You're attempting to access an http sever using https.

OgreTransporter commented 2 years ago
C:\Users\transporter>curl "http://testserver:5002/"
{"message": "The browser (or proxy) sent a request that this server could not understand."}
kamyanskiy commented 2 years ago
C:\Users\transporter>curl "http://testserver:5002/"
{"message": "The browser (or proxy) sent a request that this server could not understand."}

I copy pasted your example, and it works from scratch on my machine. So I suppose its your environment-specific issue. I see you call curl from Windows machine, but you didn't told anything about it. I advice you to search root of issue in that area.