Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't connect to Flask web service, connection refused

Tags:

python

flask

I'm trying to run a simple web server on a Raspberry Pi with Flask. When I run my Flask app, it says:

running on http://127.0.0.1:5000/

But when I enter this address on my laptop's in Chrome, I get

ERR_CONNECTION_REFUSED

I can open 127.0.0.1:5000 on the Raspberry Pi's browser. What do I need to do to connect from another computer?

like image 347
Yashar Avatar asked May 31 '15 06:05

Yashar


Video Answer


3 Answers

Run your app like this:

if __name__ == '__main__':
    app.run(host='0.0.0.0')

It will make the server externally visible. If the IP address of the machine is 192.168.X.X then, from the same network you can access it in 5000 port. Like, http://192.168.X.X:5000

like image 174
salmanwahed Avatar answered Oct 13 '22 19:10

salmanwahed


A reason could also be in firewall refusing incoming connections on port 5000. Try:

sudo ufw allow 5000
like image 15
Artem Zaytsev Avatar answered Oct 13 '22 18:10

Artem Zaytsev


when you are running the server via flask run change it to flask run --host=0.0.0.0 to connect, find the IPV4 address of the server that your script is running on. On the same network, go to http://[IPV4 address]:5000

like image 13
Sam Bernstein Avatar answered Oct 13 '22 20:10

Sam Bernstein