Answer the question
In order to leave comments, you need to log in
Can Flask/Flask Restful return HTTP 200 without being explicitly told?
I have an API method that can return (described in Return) only 2 HTTP response codes: 201 and 400. Also, I can expect HTTP 500 if something goes wrong. But when passing the tests, the API returns HTTP 200 instead of 400. How can this happen? Even when I add something like
if True:
return 400
Answer the question
In order to leave comments, you need to log in
I understand you are using Flask. https://www.flaskapi.org/api-guide/status-codes/
Okay, I found the problem. If the response contains only HTTP code, it looks like
Unfortunately, flask-restful does not handle it correctly. This results in a response with the response text "400" and HTTP code - 200. The way out is to manually create the flask.Responce object :
return Responce(status=400)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question