-1

In the Vertex AI docs it is stated "...request within 10 seconds with status code 200 OK. The contents of the response body do not matter;".

I have never used Flask before (I have used Django) but a lot of exampels on how to make a custom container is with flask. I struggle to figure out how I can return 200 OK as status code (I find that phrasing odd, since I have never seen status-codes being anything else than a number)

I have tried this

from flask import Flask,Response,make_response
.
.

@app.route('/health',methods=["GET","POST"])
def health():
    return Response("OK",status=200)


@app.route('/health',methods=["GET","POST"])
def health():
    return Response(status="200 OK")


@app.route('/health',methods=["GET","POST"])
def health():
    return make_response("200 OK")

but neither seem to work.

CutePoison
  • 4,679
  • 5
  • 28
  • 63

1 Answers1

2

Flask docs on response object mention that you have either status or status_code available.

property status: str
    The HTTP status code as a string.

property status_code: int
    The HTTP status code as a number.

This would imply that you could just use status_code in your example. Alternatively you could use a return without the response object, like so:

result = {'a': 'b'}
return result, 200

As taken from this SO question semi related to yours.

JustLudo
  • 1,690
  • 12
  • 29
  • My question is that in their docs it's written as the *status code* has to be `200 OK` and not just `200` (which implies OK). – CutePoison Mar 08 '22 at 13:09
  • That might be a language thingy vs being explicit in a technical document, since it also states to return "503 Service Unavailable", which you can imagine is also not a valid integer. It is however a valid status code as it confirms to the standard list. The OK in this case is implied after a 200 but technically up to the receiver to interpret. Bottom line, when asked for a HTTP status code, always assume just the number. – JustLudo Mar 08 '22 at 14:18