mirror of https://github.com/python/cpython
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:
parent
56b20595e6
commit
145a5f73f0
|
@ -93,12 +93,16 @@ class HTTPServer(SocketServer.TCPServer):
|
||||||
host, port = self.socket.getsockname()
|
host, port = self.socket.getsockname()
|
||||||
if not host or host == '0.0.0.0':
|
if not host or host == '0.0.0.0':
|
||||||
host = socket.gethostname()
|
host = socket.gethostname()
|
||||||
hostname, hostnames, hostaddrs = socket.gethostbyaddr(host)
|
try:
|
||||||
if '.' not in hostname:
|
hostname, hostnames, hostaddrs = socket.gethostbyaddr(host)
|
||||||
for host in hostnames:
|
except socket.error:
|
||||||
if '.' in host:
|
hostname = host
|
||||||
hostname = host
|
else:
|
||||||
break
|
if '.' not in hostname:
|
||||||
|
for host in hostnames:
|
||||||
|
if '.' in host:
|
||||||
|
hostname = host
|
||||||
|
break
|
||||||
self.server_name = hostname
|
self.server_name = hostname
|
||||||
self.server_port = port
|
self.server_port = port
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue