Search code examples
pythonapiflaskreturnboolean

return bool as POST response using flask


I'm mocking an Post api (written in C#) which return a bool value true or false when called. The content-type is application/json for the request

true

I am now trying to mock that endpoint in Python using Flask and I'm struggling to make it pass a boolean value.

I tried

return make_response(True,200)

or simply

return True

and in both cases the api fails sending the desired response and throws errors.

In a desperate attempt I tried returning "True" as a string

return make_response("True", 200)

That seemed to work at the mock level, but the consuming code (c#) fails as it tries to convert that return value into bool by

result = response.Content.ReadAsAsync<bool>().Result

Any ideas on how to make the mock api return a bool value ???


Solution

  • You should consider sending json data.

    return json.dumps(True)