<p>I am trying to implement flask-healthz (<a href="https://pypi.org/project/flask-healthz/" rel="nofollow noreferrer">https://pypi.org/project/flask-healthz/</a>) for my python application to get return on liveness and rediness probes. But somehow it doesn't work for me. Below is my code snippet :</p>
<pre><code>from flask import Flask
from flask_healthz import healthz
from flask_healthz import HealthError

def printok():
    print(&quot;Everything is fine&quot;)

app = Flask(__name__)
app.register_blueprint(healthz, url_prefix=&quot;/healthz&quot;)

def liveness():
    try:
        printok()
    except Exception:
        raise HealthError(&quot;Can't connect to the file&quot;)

def readiness():
    try:
        printok()
    except Exception:
        raise HealthError(&quot;Can't connect to the file&quot;)

HEALTHZ = {
    &quot;live&quot;: &quot;yourapp.checks.liveness&quot;,
    &quot;ready&quot;: &quot;yourapp.checks.readiness&quot;,
}

@app.route(&quot;/&quot;)
def hello():
    return &quot;Hello World!&quot;

if __name__ == &quot;__main__&quot;:
    app.run(host='0.0.0.0', port=5000)
</code></pre>
<p>And the output to the code is something like below :</p>
<pre><code>(app-root) curl http://localhost:5000/ 
127.0.0.1 - - [02/Jun/2021 01:02:56] &quot;GET / HTTP/1.1&quot; 200 -
Hello World! 



(app-root) curl http://localhost/yourapp/healthz/live
curl: (7) Failed to connect to localhost port 80: Connection refused


(app-root) curl http://localhost:5000/yourapp/healthz/live
127.0.0.1 - - [02/Jun/2021 01:03:23] &quot;GET /yourapp/healthz/live HTTP/1.1&quot; 404 -
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 3.2 Final//EN&quot;&gt;
&lt;title&gt;404 Not Found&lt;/title&gt;
&lt;h1&gt;Not Found&lt;/h1&gt;
&lt;p&gt;The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.&lt;/p&gt;


(app-root) curl http://localhost:5000/yourapp/healthz/ready
127.0.0.1 - - [02/Jun/2021 01:03:37] &quot;GET /yourapp/healthz/ready HTTP/1.1&quot; 404 -
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 3.2 Final//EN&quot;&gt;
&lt;title&gt;404 Not Found&lt;/title&gt;
&lt;h1&gt;Not Found&lt;/h1&gt;
&lt;p&gt;The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.&lt;/p&gt;


(app-root) curl http://localhost:5000/healthz/readiness
127.0.0.1 - - [02/Jun/2021 01:04:02] &quot;GET /healthz/readiness HTTP/1.1&quot; 404 -
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 3.2 Final//EN&quot;&gt;
&lt;title&gt;404 Not Found&lt;/title&gt;
&lt;h1&gt;Not Found&lt;/h1&gt;
&lt;p&gt;The readiness check endpoint is not setup&lt;/p&gt;


(app-root) curl http://localhost:5000/healthz/liveness
127.0.0.1 - - [02/Jun/2021 01:04:10] &quot;GET /healthz/liveness HTTP/1.1&quot; 404 -
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 3.2 Final//EN&quot;&gt;
&lt;title&gt;404 Not Found&lt;/title&gt;
&lt;h1&gt;Not Found&lt;/h1&gt;
&lt;p&gt;The liveness check endpoint is not setup&lt;/p&gt;
(app-root) 
</code></pre>
<p>Is there something I am doing wrong. I tried to run the same in Openshift well but no luck.</p>
<p>I would appriciate if there is some working example.</p>

dataplumber
<p>Assuming this is a copy-paste from the documentation, here is what you can change to make it work.</p>
<p>flat <code>app.py</code>:</p>
<pre><code>from flask import Flask
from flask_healthz import healthz
from flask_healthz import HealthError

app = Flask(__name__)
app.register_blueprint(healthz, url_prefix=&quot;/healthz&quot;)

def printok():
    print(&quot;Everything is fine&quot;)

def liveness():
    try:
        printok()
    except Exception:
        raise HealthError(&quot;Can't connect to the file&quot;)

def readiness():
    try:
        printok()
    except Exception:
        raise HealthError(&quot;Can't connect to the file&quot;)

app.config.update(
    HEALTHZ = {
        &quot;live&quot;: &quot;app.liveness&quot;,
        &quot;ready&quot;: &quot;app.readiness&quot;,
    }
)

@app.route(&quot;/&quot;)
def hello():
    return &quot;Hello World!&quot;

if __name__ == &quot;__main__&quot;:
    app.run(host='0.0.0.0', port=5000)
</code></pre>
<p>then</p>
<pre><code>curl localhost:5000/healthz/live
OK

curl localhost:5000/healthz/ready
OK
</code></pre>
