]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Don't just die if gethostbyaddr() fails -- as it can when DNS is
authorGuido van Rossum <guido@python.org>
Wed, 9 Jun 1999 15:05:47 +0000 (15:05 +0000)
committerGuido van Rossum <guido@python.org>
Wed, 9 Jun 1999 15:05:47 +0000 (15:05 +0000)
unreachable -- but fall back to using whatever hostname we have.

Lib/BaseHTTPServer.py

index e496d6757829dbdd313718a32b666da719f23797..8399267bd30647eb7593640c9acdd6ff79d832b7 100644 (file)
@@ -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