[New-bugs-announce] [issue15134] urllib.request.thishost() fails on OSX 10.7

Ronald Oussoren report at bugs.python.org
Fri Jun 22 11:34:45 CEST 2012

New submission from Ronald Oussoren <ronaldoussoren at mac.com>:

I just noticed that test_urllib fails for me because urllib.request.thishost() fails:

ERROR: test_thishost (test.test_urllib.Utility_Tests)
Test the urllib.request.thishost utility function returns a tuple
Traceback (most recent call last):
  File "/Users/ronald/Projects/python/rw/default/Lib/test/test_urllib.py", line 1155, in test_thishost
    self.assertIsInstance(urllib.request.thishost(), tuple)
  File "/Users/ronald/Projects/python/rw/default/Lib/urllib/request.py", line 2236, in thishost
    _thishost = tuple(socket.gethostbyname_ex(socket.gethostname())[2])
socket.gaierror: [Errno 8] nodename nor servname provided, or not known


This is because this host's hostname (Gondolin.local) is not in DNS because my mDNSReponder detected a conflict and picked a different name to advertise in the .local zone without updating the hostname.

The reason I report this anyway is that URLopener.open_local_file seems to assume that thishost() cannot fail, and the error condition on my machine could easily happen on other systems as well.

BTW. The use of this host() in URLopener.open_local_file is wrong for other reasons as well: it assumes that the local machine has exactly 1 IP address, and won't correctly detect that a file is local when the IP address is one of the other IP addresses on a multi homed system.

components: Library (Lib)
messages: 163389
nosy: ronaldoussoren
priority: normal
severity: normal
status: open
title: urllib.request.thishost() fails on OSX 10.7
versions: Python 3.3

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list