]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix thishost helper funtion in urllib. Returns the ipaddress of localhost when
authorSenthil Kumaran <senthil@uthcode.com>
Sat, 1 Jun 2013 18:12:17 +0000 (11:12 -0700)
committerSenthil Kumaran <senthil@uthcode.com>
Sat, 1 Jun 2013 18:12:17 +0000 (11:12 -0700)
hostname is resolvable by socket.gethostname for local machine. This all fixes
certain freebsd builtbot failures.

Lib/urllib/request.py

index 1279322496f0ee129710dbf97d3b9f78cc054c77..30e43e6f9f9170393a69cadbc1de044aeadd5c4f 100644 (file)
@@ -2229,7 +2229,10 @@ def thishost():
     """Return the IP addresses of the current host."""
     global _thishost
     if _thishost is None:
-        _thishost = tuple(socket.gethostbyname_ex(socket.gethostname())[2])
+        try:
+            _thishost = tuple(socket.gethostbyname_ex(socket.gethostname())[2])
+        except socket.gaierror:
+            _thishost = tuple(socket.gethostbyname_ex('localhost')[2])
     return _thishost
 
 _ftperrors = None