Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dcdadfe

Browse files
committed
Fix thishost helper funtion in urllib. Returns the ipaddress of localhost when
hostname is resolvable by socket.gethostname for local machine. This all fixes certain freebsd builtbot failures.
1 parent 4e42ae8 commit dcdadfe

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

Lib/urllib/request.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2229,7 +2229,10 @@ def thishost():
22292229
"""Return the IP addresses of the current host."""
22302230
global _thishost
22312231
if _thishost is None:
2232-
_thishost = tuple(socket.gethostbyname_ex(socket.gethostname())[2])
2232+
try:
2233+
_thishost = tuple(socket.gethostbyname_ex(socket.gethostname())[2])
2234+
except socket.gaierror:
2235+
_thishost = tuple(socket.gethostbyname_ex('localhost')[2])
22332236
return _thishost
22342237

22352238
_ftperrors = None

0 commit comments

Comments
 (0)