_socket.getaddrinfo returning EAI_NONAME for ".local" hostnames?
Bug report
Bug description:
Caveat Emptor: I'm not a Python programmer and I'm trying to debug a relatively complicated local Python script which has started failing with Python3.13.
We have code running on Mac OS Tahoe (26.2) using the URL request library to retrieve URL resources from a local host which is in the .local domain. This code works under Python3.12, but fails after that with this error:
Traceback (most recent call last):
File "/opt/homebrew/Cellar/[email protected]/3.14.2/Frameworks/Python.framework/Versions/3.14/lib/python3.14/urllib/request.py", line 1321, in do_open
h.request(req.get_method(), req.selector, req.data, headers,
~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
encode_chunked=req.has_header('Transfer-encoding'))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/[email protected]/3.14.2/Frameworks/Python.framework/Versions/3.14/lib/python3.14/http/client.py", line 1358, in request
self._send_request(method, url, body, headers, encode_chunked)
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/[email protected]/3.14.2/Frameworks/Python.framework/Versions/3.14/lib/python3.14/http/client.py", line 1404, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/[email protected]/3.14.2/Frameworks/Python.framework/Versions/3.14/lib/python3.14/http/client.py", line 1353, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/[email protected]/3.14.2/Frameworks/Python.framework/Versions/3.14/lib/python3.14/http/client.py", line 1113, in _send_output
self.send(msg)
~~~~~~~~~^^^^^
File "/opt/homebrew/Cellar/[email protected]/3.14.2/Frameworks/Python.framework/Versions/3.14/lib/python3.14/http/client.py", line 1057, in send
self.connect()
~~~~~~~~~~~~^^
File "/opt/homebrew/Cellar/[email protected]/3.14.2/Frameworks/Python.framework/Versions/3.14/lib/python3.14/http/client.py", line 1023, in connect
self.sock = self._create_connection(
~~~~~~~~~~~~~~~~~~~~~~~^
(self.host,self.port), self.timeout, self.source_address)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/[email protected]/3.14.2/Frameworks/Python.framework/Versions/3.14/lib/python3.14/socket.py", line 846, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/[email protected]/3.14.2/Frameworks/Python.framework/Versions/3.14/lib/python3.14/socket.py", line 984, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
I'm still trying to debug what's going on here.
CPython versions tested on:
3.14
Operating systems tested on:
macOS
Note that this could also be related to some DNS issue with Mac OS Tahoe (26.2) and .local hostnames that is interacting in a strange way with Python ... I'm going to try to figure out how to convince the Mac OS brew stuff to downgrade my installed Python to Python3.12 to see if that does indeed "fix" things ...
I just removed all of the python3 packages (3.11, 3.12, 3.13, and 3.14) from my system, and then installed 3.12. No luck. I'm still seeing an error in getaddrinfo() ... so this may be a Python versus Mac OS 26.2 (Tahoe) issue with .local addresses ...
It works for me (3.12 and 3.14) on macOS 26.2, both installed using the installer on python.org.
One thing to check is the system configuration: resolving ".local" addresses requires additional privlleges: In System Settings to to Privay & Security, then Local Network and check that Python is present there and enabled (it is on my laptop). Disabling the setting also breaks resolving ".local" addresses.
You may have to give the terminal this privilege if the Python you're using is not a framework install.
See https://developer.apple.com/documentation/technotes/tn3179-understanding-local-network-privacy for background information at Apple.
I'm closing the issue because you're running into a macOS security feature, that's not something we can fix on our end.
Thanks @ronaldoussoren for the follow up and the pointer to the Mac OS 26.2 documentation.
It looks like there's no way to manually add any application to System Settings -> Privacy & Security -> Local Network. All the documentation I've found indicates that Applications have to be modified to "Request Local Network Access" in order for a popup to appear making it possible for the user to click "Yes". (sigh)
Looks like I'm screwed and I'm going to have to give up using my MacBook Pro for development.
Ah, new information:
This problem affects the brew installed version of Python in /opt/homebrew/bin/python3, not the Apple supplied version in /usr/bin/python3. So obviously Apple has done something to their version. (sigh) It would be nice if Apple would contribute back whatever changes are required to make this work.
Ah, new information:
This problem affects the
brewinstalled version of Python in/opt/homebrew/bin/python3, not the Apple supplied version in/usr/bin/python3. So obviously Apple has done something to their version. (sigh) It would be nice if Apple would contribute back whatever changes are required to make this work.
It might be related to code signing. Our installer installs signed binaries and does end up in system settings for me.
Annoyingly it is not only not possible to manually add apps to these settings, I can also not remove one to test what happens (I'd expect that 'tccutil' could be used for that, but it doesn't do anything for me).