'This site can’t be reached [flask, python]

when I open the link 0.0.0.0:5000 in my browser I always get the message on the browser "This site can't be reached" the code seems to be working since I get this message on the console

Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)

enter image description here

here is the code that I am using

from flask import Flask, render_template, request
from scipy.misc import imsave, imread, imresize
import numpy as np
import keras.models
import re
import sys
import os
from load import *

sys.path.append(os.path.abspath('./model'))
app = Flask(__name__)
global model, graph
model, graph = init()

def convertImage(imData):
    imgstr = re.search(r'base64(.*'.imData).group(1)
    with open('output.png', 'wb') as output:
        output.write(imgstr.decode('base64'))

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/predict', methods=['GET', 'POST'])
def predict():
    imData = request.get_data()
    convertImage(imData)
    x = imread('output.png', mode = 'L')
    x = np.invert(x)
    x = imresize(x, 48, 48)
    x = x.reshape(1,48,48,1)
    with graph.as_default():
        out = model.predict(x)
        response = np.array_str(np.argmax(out))
        return response



if __name__ == "__main__":
    port = int(os.environ.get('PORT', 5000))
    app.run(host='0.0.0.0', port=port)


Solution 1:[1]

For me using app.run(debug=False) worked when using

port = int(os.environ.get('PORT', 5000))
app.run(host='0.0.0.0', port=port)

did not.

I can't tell if this is a firewall issue or why it didn't work. Do note that after doing this it started hosting at http://127.0.0.1:5000/.

Solution 2:[2]

Both http://127.0.0.1:5000 and http://localhost:5000 are correct use it instead of 0.0.0.0

Solution 3:[3]

definitely use, ur local host with 127.0.0.1 instead of 0.0.0.0

Solution 4:[4]

To test locally, instead of http://0.0.0.0:5000, you can use http://localhost:5000

Solution 5:[5]

For me using localhost instead of 0.0.0.0

like this:

 app.run(host='localhost', port=5000, debug=True)

Solution 6:[6]

Always run docker in detached mode, in my case I tried running docker in detached mode and it worked. As we want to access the URL in browser. i.e. outside the container, The best solution is to run in detached mode and by exposing the port.

 docker run -d -p 5000:5000 flask_docker_practise

Above we are passing -d to run container in detached mode and then we pass -p to let the container know on which port we want to expose and listen.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Pro Q
Solution 2 Jean Bouez
Solution 3 Elvin Aghammadzada
Solution 4 Kanishk Mair
Solution 5 Nik
Solution 6 Harvindar Singh Garcha