I have build a flask app in docker from nvidia/cuda:12.5.1-cudnn-runtime-ubuntu22.04
. But this flask cannot receive any utf-8
request with the Bad request syntax
error.
# here the messy code ä½xa0好 is 你好 in Chinese, which means hello
code 400, message Bad request syntax ('GET /chat?question=ä½xa0好 HTTP/1.1')
For English characters that the query question=hello
, everything works fine. I tried to set app.json.ensure_ascii = False
and set the charset=UTF-8
in curl, but got the same error.
However, when I launch the app with gunicorn
, it works. By the way, I set the locales of the docker image to Chinese, so probably it’s not the system problem.
This is the demo code:
from flask import Flask, request
app = Flask(__name__)
app.json.ensure_ascii = False
@app.route("/chat", methods=["GET"])
def chat():
query = request.args.get("question")
print(query)
return query
@app.route("/")
def test():
return "你好"
if __name__ == "__main__":
app.run(host="0.0.0.0", port=10132, debug=True)
1