From 145a5f73f0064b3779e3f0a592112615a6d0fb5d Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Wed, 9 Jun 1999 15:05:47 +0000 Subject: [PATCH] Don't just die if gethostbyaddr() fails -- as it can when DNS is unreachable -- but fall back to using whatever hostname we have. --- Lib/BaseHTTPServer.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Lib/BaseHTTPServer.py b/Lib/BaseHTTPServer.py index e496d67578..8399267bd3 100644 --- a/Lib/BaseHTTPServer.py +++ b/Lib/BaseHTTPServer.py @@ -93,12 +93,16 @@ class HTTPServer(SocketServer.TCPServer): host, port = self.socket.getsockname() if not host or host == '0.0.0.0': host = socket.gethostname() - hostname, hostnames, hostaddrs = socket.gethostbyaddr(host) - if '.' not in hostname: - for host in hostnames: - if '.' in host: - hostname = host - break + try: + hostname, hostnames, hostaddrs = socket.gethostbyaddr(host) + except socket.error: + hostname = host + else: + if '.' not in hostname: + for host in hostnames: + if '.' in host: + hostname = host + break self.server_name = hostname self.server_port = port -- 2.40.0