Python flask Server fails to bind and start

Hello all. I'm having some trouble figuring out why my flask server is having trouble starting up on my OpenWRT machine. The server is meant to enable easy configuration of other programs running on the machine. There are many odd details to this problem, however.

Firstly, attempting to start it up looks like this:

root@OpenWrt:~/flaskr# flask run -host=192.168.1.1
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
Traceback (most recent call last):
  File "/usr/bin/flask", line 33, in <module>
    sys.exit(load_entry_point('Flask==2.0.2', 'console_scripts', 'flask')())
  File "/usr/lib/python3.10/site-packages/flask/cli.py", line 994, in main
 .......
  File "/usr/lib/python3.10/socketserver.py", line 466, in server_bind
socket.gaierror: [Errno -3] Try again

I thought this perhaps means we cant bind to the interface? However I have been able to start up the server before. The circumstances under which are seemingly similar to the current circumstances! In other words, nothing has really changed since then. Obviously that I know of.

Here's the output of netstat, which I used to see if something was stopping it from getting the socket connection.

root@OpenWrt:~/flaskr# netstat -lp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:www             0.0.0.0:*               LISTEN      1405/uhttpd
tcp        0      0 192.168.0.184:domain    0.0.0.0:*               LISTEN      2237/dnsmasq
tcp        0      0 localhost:domain        0.0.0.0:*               LISTEN      2237/dnsmasq
tcp        0      0 OpenWrt.lan:domain      0.0.0.0:*               LISTEN      2237/dnsmasq
tcp        0      0 192.168.2.1:domain      0.0.0.0:*               LISTEN      2237/dnsmasq
tcp        0      0 0.0.0.0:ssh             0.0.0.0:*               LISTEN      1052/dropbear
tcp        0      0 :::www                  :::*                    LISTEN      1405/uhttpd
tcp        0      0 <some ipv6 address which im not sure if I can post>:domain :::*                    LISTEN      2237/dnsmasq
tcp        0      0 <some ipv6 address which im not sure if I can post>:domain :::*                    LISTEN      2237/dnsmasq
tcp        0      0 <some ipv6 address which im not sure if I can post>:domain :::*                    LISTEN      2237/dnsmasq
tcp        0      0 localhost:domain        :::*                    LISTEN      2237/dnsmasq
tcp        0      0 OpenWrt.lan:domain      :::*                    LISTEN      2237/dnsmasq
tcp        0      0 <some ipv6 address which im not sure if I can post>:domain :::*                    LISTEN      2237/dnsmasq
tcp        0      0 <some ipv6 address which im not sure if I can post>:domain :::*                    LISTEN      2237/dnsmasq
tcp        0      0 :::ssh                  :::*                    LISTEN      1052/dropbear
udp        0      0 192.168.0.184:domain    0.0.0.0:*                           2237/dnsmasq
udp        0      0 localhost:domain        0.0.0.0:*                           2237/dnsmasq
udp        0      0 OpenWrt.lan:domain      0.0.0.0:*                           2237/dnsmasq
udp        0      0 192.168.2.1:domain      0.0.0.0:*                           2237/dnsmasq
udp        0      0 0.0.0.0:bootps          0.0.0.0:*                           2237/dnsmasq
udp        0      0 :::dhcpv6-server        :::*                                1280/odhcpd
udp        0      0 <some ipv6 address which im not sure if I can post>:domain :::*                                2237/dnsmasq
udp        0      0 <some ipv6 address which im not sure if I can post>:domain :::*                                2237/dnsmasq
udp        0      0 <some ipv6 address which im not sure if I can post>:domain :::*                                2237/dnsmasq
udp        0      0 localhost:domain        :::*                                2237/dnsmasq
udp        0      0 OpenWrt.lan:domain      :::*                                2237/dnsmasq
udp        0      0 <some ipv6 address which im not sure if I can post>:domain :::*                                2237/dnsmasq
udp        0      0 <some ipv6 address which im not sure if I can post>:domain :::*                                2237/dnsmasq
raw        0      0 ::%159:58               ::%4239293:*            58          1280/odhcpd
Active UNIX domain sockets (only servers)
Proto RefCnt Flags       Type       State         I-Node PID/Program name    Path
unix  2      [ ACC ]     STREAM     LISTENING        191 469/ubusd           /var/run/ubus/ubus.sock

Here's my various /etc/config network related files

root@OpenWrt:~/flaskr# cat /etc/config/network
config interface 'loopback'
        option device 'lo'
        option proto 'static'
        option ipaddr '127.0.0.1'
        option netmask '255.0.0.0'

config globals 'globals'
        option ula_prefix 'fd37:8453:da23::/48'

config device
        option name 'br-lan'
        option type 'bridge'
        list ports 'eth0.1'

config interface 'lan'
        option device 'br-lan'
        option proto 'static'
        option ipaddr '192.168.1.1'
        option netmask '255.255.255.0'
        option ip6assign '60'

config device
        option name 'br-vlan'
        option type 'bridge'
        list ports 'eth0.3'

config interface 'vlan'
        option device 'br-vlan'
        option proto 'static'
        option ipaddr '192.168.2.1'
        option netmask '255.255.255.0'

config device
        option name 'eth0.2'
        option macaddr '0c:cf:89:6f:9b:f8'

config interface 'wan'
        option device 'eth0.2'
        option proto 'dhcp'

config interface 'wan6'
        option device 'eth0.2'
        option proto 'dhcpv6'

config switch
        option name 'switch0'
        option reset '1'
        option enable_vlan '1'

config switch_vlan
        option device 'switch0'
        option vlan '1'
        option ports '1 2 3 4 6t'

config switch_vlan
        option device 'switch0'
        option vlan '2'
        option ports '0 6t'

config interface 'wwan'
        option proto 'dhcp'
root@OpenWrt:~/flaskr# cat /etc/config/firewall
config defaults
        option input 'ACCEPT'
        option output 'ACCEPT'
        option forward 'ACCEPT'
        option synflood_protect '1'

config zone
        option name 'lan'
        option input 'ACCEPT'
        option output 'ACCEPT'
        option forward 'ACCEPT'
        list network 'lan'

config zone
        option name 'wan'
        option input 'REJECT'
        option output 'ACCEPT'
        option forward 'REJECT'
        option masq '1'
        option mtu_fix '1'
        list network 'wan'
        list network 'wan6'
        list network 'wwan'

config zone
        option name 'vlan'
        option input 'ACCEPT'
        option output 'ACCEPT'
        option forward 'REJECT'
        list network 'vlan'

config rule
        option name 'Allow Provisioning Server'
        option src 'vlan'
        option proto 'tcp'
        option dest_port '25565'
        option target 'ACCEPT'

config forwarding
        option src 'lan'
        option dest 'wan'



config rule
        option name 'Allow-DHCP-Renew'
        option src 'wan'
        option proto 'udp'
        option dest_port '68'
        option target 'ACCEPT'
        option family 'ipv4'

config rule
        option name 'Allow-Ping'
        option src 'wan'
        option proto 'icmp'
        option icmp_type 'echo-request'
        option family 'ipv4'
        option target 'ACCEPT'

config rule
        option name 'Allow-IGMP'
        option src 'wan'
        option proto 'igmp'
        option family 'ipv4'
        option target 'ACCEPT'

config rule
        option name 'Allow-DHCPv6'
        option src 'wan'
        option proto 'udp'
        option src_ip 'fc00::/6'
        option dest_ip 'fc00::/6'
        option dest_port '546'
        option family 'ipv6'
        option target 'ACCEPT'

config rule
        option name 'Allow-MLD'
        option src 'wan'
        option proto 'icmp'
        option src_ip 'fe80::/10'
        list icmp_type '130/0'
        list icmp_type '131/0'
        list icmp_type '132/0'
        list icmp_type '143/0'
        option family 'ipv6'
        option target 'ACCEPT'

config rule
        option name 'Allow-ICMPv6-Input'
        option src 'wan'
        option proto 'icmp'
        list icmp_type 'echo-request'
        list icmp_type 'echo-reply'
        list icmp_type 'destination-unreachable'
        list icmp_type 'packet-too-big'
        list icmp_type 'time-exceeded'
        list icmp_type 'bad-header'
        list icmp_type 'unknown-header-type'
        list icmp_type 'router-solicitation'
        list icmp_type 'neighbour-solicitation'
        list icmp_type 'router-advertisement'
        list icmp_type 'neighbour-advertisement'
        option limit '1000/sec'
        option family 'ipv6'
        option target 'ACCEPT'

config rule
        option name 'Allow-ICMPv6-Forward'
        option src 'wan'
        option dest '*'
        option proto 'icmp'
        list icmp_type 'echo-request'
        list icmp_type 'echo-reply'
        list icmp_type 'destination-unreachable'
        list icmp_type 'packet-too-big'
        list icmp_type 'time-exceeded'
        list icmp_type 'bad-header'
        list icmp_type 'unknown-header-type'
        option limit '1000/sec'
        option family 'ipv6'
        option target 'ACCEPT'

config rule
        option name 'Allow-IPSec-ESP'
        option src 'wan'
        option dest 'lan'
        option proto 'esp'
        option target 'ACCEPT'

config rule
        option name 'Allow-ISAKMP'
        option src 'wan'
        option dest 'lan'
        option dest_port '500'
        option proto 'udp'
        option target 'ACCEPT'

config rule
        option name 'Support-UDP-Traceroute'
        option src 'wan'
        option dest_port '33434:33689'
        option proto 'udp'
        option family 'ipv4'
        option target 'REJECT'
        option enabled 'false'

config include
        option path '/etc/firewall.user'

As I write this post, I just tried to start it up again, and it worked! It looks like this:

root@OpenWrt:~/flaskr# flask run --host=192.168.1.1
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://192.168.1.1:5000/ (Press CTRL+C to quit)

All I've been doing is viewing files, and re setting the wifi configuration with "wifi" on bash. What could be causing this?

Well. Turns out I missed an important detail. Doing "flask run -h 192.168.1.1" was 100 percent necessary for making it start up properly. I'm assuming this is an address validation / argument parsing bug on behalf of flask, considering it worked on few occasions with the wrong command.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.