[New-bugs-announce] [issue35164] socket.getfqdn and socket.gethostbyname fail on MacOS

Sorin Sbarnea report at bugs.python.org
Sun Nov 4 11:50:41 EST 2018

New submission from Sorin Sbarnea <sorin.sbarnea at gmail.com>:

It seems that when the MacOS machine does not have a FQDN name manually configured using `scutil`, python will be fail to resolve domain names and timeout after ~30 seconds.

I mention that the DNS resolution works correctly on the machine and that the DHCP servers provides one ore more domains to be useles for resolution. Tools like nslookup or ping are not affected by this, only python (tried py27,34-36 and got same behavior).

Usually python user encounters errors like:

Traceback (most recent call last):
gaierror: [Errno 8] nodename nor servname provided, or not known

One these machines `hostname` cli command returns a valid FQDN name like `foo.lan` but scutil will not return one:
sudo scutil --get HostName
HostName: not set

One temporary workaround is to manually run:
sudo scutil --set HostName `hostname`

This will set the hostname and python sockets functions will start to work (after few minutes as some caching is involved).

Still, we cannot expect users to run this command themselves. Even worse, they would have to re-run this each time the roam to another network that may have a different set of domains.

See: https://stackoverflow.com/questions/52602107

components: macOS
messages: 329237
nosy: ned.deily, ronaldoussoren, ssbarnea
priority: normal
severity: normal
status: open
title: socket.getfqdn and socket.gethostbyname fail on MacOS
type: behavior
versions: Python 2.7, Python 3.4, Python 3.5, Python 3.6, Python 3.7

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list