From 71976ff8265570c096f7d7c5fb641c736c145e50 Mon Sep 17 00:00:00 2001 From: ATATC Date: Mon, 22 Apr 2024 14:13:17 -0400 Subject: [PATCH] Bug fixed: possible error when getting hostname. (#110) --- leads/comm/prototype.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/leads/comm/prototype.py b/leads/comm/prototype.py index 3ab9397c..b15a17dd 100644 --- a/leads/comm/prototype.py +++ b/leads/comm/prototype.py @@ -1,6 +1,6 @@ from abc import abstractmethod as _abstractmethod, ABCMeta as _ABCMeta from socket import socket as _socket, AF_INET as _AF_INET, SOCK_STREAM as _SOCK_STREAM, \ - gethostbyname_ex as _gethostbyname_ex, gethostname as _gethostname + gethostbyname_ex as _gethostbyname_ex, gethostname as _gethostname, gaierror as _gaierror from threading import Lock as _Lock, Thread as _Thread from typing import Self as _Self, Callable as _Callable, override as _override @@ -9,7 +9,10 @@ def my_ip_addresses() -> list[str]: - return [ip for ip in _gethostbyname_ex(_gethostname())[2] if not ip.startswith("127.")] + try: + return [ip for ip in _gethostbyname_ex(_gethostname())[2] if not ip.startswith("127.")] + except _gaierror: + return [] class Service(metaclass=_ABCMeta):