Commit 145a5f73 authored by Guido van Rossum's avatar Guido van Rossum

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

unreachable -- but fall back to using whatever hostname we have.
parent 56b20595
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment