From: Guido van Rossum Date: Wed, 9 Jun 1999 15:05:47 +0000 (+0000) Subject: Don't just die if gethostbyaddr() fails -- as it can when DNS is X-Git-Tag: v1.6a1~1267 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=145a5f73f0064b3779e3f0a592112615a6d0fb5d;p=thirdparty%2FPython%2Fcpython.git Don't just die if gethostbyaddr() fails -- as it can when DNS is unreachable -- but fall back to using whatever hostname we have. --- diff --git a/Lib/BaseHTTPServer.py b/Lib/BaseHTTPServer.py index e496d6757829..8399267bd306 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