Fix get_ip when no external network (#9700)

This commit is contained in:
ybyang
2025-08-28 01:28:52 +08:00
committed by GitHub
parent db0831e019
commit fd18995cf3

View File

@@ -1964,6 +1964,15 @@ def get_ip() -> str:
except Exception:
pass
# try using hostname
hostname = socket.gethostname()
try:
ip_addr = socket.gethostbyname(hostname)
warnings.warn("using local ip address: {}".format(ip_addr))
return ip_addr
except Exception:
pass
warnings.warn(
"Failed to get the IP address, using 0.0.0.0 by default."
"The value can be set by the environment variable"