Flask Webserver not reachable..?- Homenetwork

Having issues with your DietPi installation or found a bug? Post it here.
Post Reply
AnBad
Posts: 26
Joined: Sat Jan 12, 2019 4:40 pm

Flask Webserver not reachable..?- Homenetwork

Post by AnBad »

Hi,

I wrote a small Python script which should act as webserver based on Flask.

But I cant reach the server, although I am quit sure the server is up.

Is there some kind of firewall which I have to config that I can reach the Webpage from another Computer? Or might it be that lighttpd is blocking my flaskserver? How can I test if the lighttpd server is runing?

Kind regards.

Code: Select all

from flask import Flask

app = Flask(__name__)

@app.route('/')
def index():
	return "Test"

if __name__ == "__main__":
	app.run(debug=True)

User avatar
Joulinar
Posts: 5115
Joined: Sat Nov 16, 2019 12:49 am

Re: Flask Webserver not reachable..?- Homenetwork

Post by Joulinar »

Hi,

many thanks for your message. If you have lighttpd, it will prevent other web server to start. Because, port 80 (http) can be used once only per server. It's not possible to have 2 web server running on same port. You would need to configure one web server to LISTEN on another port.

To check which port are in use, you can run following.

Code: Select all

ss -tulpn | grep LISTEN
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
AnBad
Posts: 26
Joined: Sat Jan 12, 2019 4:40 pm

Re: Flask Webserver not reachable..?- Homenetwork

Post by AnBad »

Hi,
thank you. I think lighttpd is not running. That was not the problem.
Yesterday I had the same config on Raspbian. It worked without a problem. I could reach the server under 192.168.178.52. But DietPi ..?

These are the results:

Code: Select all

/mnt/usbStick/hps$ ss -tulpn | grep LISTEN
tcp     LISTEN   0        128            127.0.0.1:5000          0.0.0.0:*       users:(("python3",pid=667,fd=4),("python3",pid=667,fd=3),("python3",pid=642,fd=3))
tcp     LISTEN   0        128              0.0.0.0:22            0.0.0.0:*       users:(("sshd",pid=353,fd=3))                                                  
tcp     LISTEN   0        128                 [::]:22               [::]:*       users:(("sshd",pid=353,fd=4))       
User avatar
Joulinar
Posts: 5115
Joined: Sat Nov 16, 2019 12:49 am

Re: Flask Webserver not reachable..?- Homenetwork

Post by Joulinar »

there is no web server running on port 80. Of course you are not able to reach it that way. You need to find out why your web server did not start.
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
AnBad
Posts: 26
Joined: Sat Jan 12, 2019 4:40 pm

Re: Flask Webserver not reachable..?- Homenetwork

Post by AnBad »

Hi, tank you.

The Flask-Server is running under '127.0.0.1:5000'. I dont know, where to change this into :80 or even 192.168.178.52:80.

Is it imporatant to change it to :80?

....
Find the answer meanwhile:

Yes it is. I solved the problem thanks to duckduckgo.com. I had to ad the IP and Port in the script as follows. Thanks to you all. And sorry for bothering you. I just starting into pyhton and coding.

Code: Select all

from flask import Flask

app = Flask(__name__)

@app.route('/')
@app.route('/home')
def index():
	return "Test"

if __name__ == "__main__":
	app.run(debug=True, host='192.168.178.52', port=80)
User avatar
Joulinar
Posts: 5115
Joined: Sat Nov 16, 2019 12:49 am

Re: Flask Webserver not reachable..?- Homenetwork

Post by Joulinar »

Hi,

you have now restricted your web server to LISTEN on IP address 192.168.178.52 only. This might not be that flexible. You could try using 0.0.0.0 instead. This should allow your web server to listen on ALL interfaces and IP address. In case you change it, you don't need to reconfigure your script.

Code: Select all

app.run(debug=True, host='0.0.0.0', port=80)
At least that how other web server are configured :)

Code: Select all

tcp     LISTEN   0        1024             0.0.0.0:80             0.0.0.0:*      users:(("lighttpd",pid=22979,fd=4))
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
Post Reply