This site can’t be reached [flask, python]
Solution 1
In general, this message
Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
informs you about the IP-address of your PC that will be listened to accept the request. It can be configured to listen to only one IP-address.
As it has been stated in the comments, if you are trying to reach your Web site from the same PC you develop on, you may use virtual (loop) address 127.0.0.1
. In case you want to check how your Web site will look on your other devices that are connected to the same network (i.e. tablet, phone, other PC whatever else), you need to type your PC's internal network IP address, and it differs from the loop. It may be e.g. 192.168.1.1 (you should check it on your NIC properties). And it may changes if you try to make something like live-demo to your friends.
So in order, to prevent you from checking each time, which one IP-address is valid for your PC right now, you can use 0.0.0.0
telling to your application 'listen for incoming requests from ALL the NICs, whatever IP-address they have'.
Solution 2
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 3
Both http://127.0.0.1:5000 and http://localhost:5000 are correct use it instead of 0.0.0.0
Related videos on Youtube
Oussama
Updated on September 29, 2022Comments
-
Oussama over 1 year
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)
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)
-
kindall over 6 years0.0.0.0 is not a valid IP address, so you can't actually connect to it. When the server says it's "runinng on 0.0.0.0" it means it is accepting connections on any network adapter, not a specific one. Use 127.0.0.1 to actually connect to a server running on your machine.
-
Oussama over 6 yearsI tried that actually and it is not working, it was working before using 0.0.0.0:5000 but now I don't know what is the problem
-
-
Pro Q about 5 yearsIs there any reason why
0.0.0.0
would not work when127.0.0.1
does work? Doesn't0.0.0.0
just listen for strictly more? -
wanderlust about 5 yearsWould not work where? If you try to reach
0.0.0.0
- there is no such IP in your network. If you want to bind something to0.0.0.0
and it doesn't work, this case must be investigated, right now I cannot imagine any option why it shouldn't work.