diff options
author | Guido van Rossum <guido@python.org> | 1999-06-09 15:05:47 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1999-06-09 15:05:47 (GMT) |
commit | 145a5f73f0064b3779e3f0a592112615a6d0fb5d (patch) | |
tree | 91b79d5cd13d071dd99f89df376ae584c4f9d962 /Lib | |
parent | 56b20595e6eba948ff86db24c2ce55bae70aa659 (diff) | |
download | cpython-145a5f73f0064b3779e3f0a592112615a6d0fb5d.zip cpython-145a5f73f0064b3779e3f0a592112615a6d0fb5d.tar.gz cpython-145a5f73f0064b3779e3f0a592112615a6d0fb5d.tar.bz2 |
Don't just die if gethostbyaddr() fails -- as it can when DNS is
unreachable -- but fall back to using whatever hostname we have.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/BaseHTTPServer.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/Lib/BaseHTTPServer.py b/Lib/BaseHTTPServer.py index e496d67..8399267 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 |