Don't just die if gethostbyaddr() fails -- as it can when DNS is

unreachable -- but fall back to using whatever hostname we have.
This commit is contained in:
Guido van Rossum 1999-06-09 15:05:47 +00:00
parent 56b20595e6
commit 145a5f73f0
1 changed files with 10 additions and 6 deletions

View File

@ -93,7 +93,11 @@ class HTTPServer(SocketServer.TCPServer):
host, port = self.socket.getsockname()
if not host or host == '0.0.0.0':
host = socket.gethostname()
try:
hostname, hostnames, hostaddrs = socket.gethostbyaddr(host)
except socket.error:
hostname = host
else:
if '.' not in hostname:
for host in hostnames:
if '.' in host: