cpython icon indicating copy to clipboard operation
cpython copied to clipboard

_socket.getaddrinfo returning EAI_NONAME for ".local" hostnames?

Open fungible-leedom opened this issue 1 month ago • 3 comments

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

fungible-leedom avatar Dec 16 '25 18:12 fungible-leedom

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 ...

fungible-leedom avatar Dec 16 '25 18:12 fungible-leedom

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 ...

fungible-leedom avatar Dec 16 '25 18:12 fungible-leedom

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.

ronaldoussoren avatar Dec 16 '25 20:12 ronaldoussoren

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.

ronaldoussoren avatar Dec 18 '25 15:12 ronaldoussoren

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.

fungible-leedom avatar Dec 18 '25 19:12 fungible-leedom

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.

fungible-leedom avatar Dec 18 '25 21:12 fungible-leedom

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.

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).

ronaldoussoren avatar Dec 19 '25 08:12 ronaldoussoren