Explorar o código

Merge pull request #900 from zauberzeug/socket_failures

Ignore socket failures and just use localhost
Rodja Trappe %!s(int64=2) %!d(string=hai) anos
pai
achega
0840371bed
Modificáronse 1 ficheiros con 4 adicións e 1 borrados
  1. 4 1
      nicegui/nicegui.py

+ 4 - 1
nicegui/nicegui.py

@@ -85,7 +85,10 @@ def print_welcome_message():
     port = os.environ['NICEGUI_PORT']
     ips = set()
     if host == '0.0.0.0':
-        ips.update(set(info[4][0] for info in socket.getaddrinfo(socket.gethostname(), None) if len(info[4]) == 2))
+        try:
+            ips.update(set(info[4][0] for info in socket.getaddrinfo(socket.gethostname(), None) if len(info[4]) == 2))
+        except Exception:
+            pass  # NOTE: if we can't get the host's IP, we'll just use localhost
     ips.discard('127.0.0.1')
     addresses = [(f'http://{ip}:{port}' if port != '80' else f'http://{ip}') for ip in ['localhost'] + sorted(ips)]
     if len(addresses) >= 2: