macos – Python on Terminal can’t resolve DNS queries


I’ve a bizarre challenge with Python on macOS Sequoia for the final couple of days. It didn’t occur proper after the improve, it labored initially. Python in Terminal.app can’t resolve any DNS queries. Nevertheless, the Python console and the builtin Terminal in PyCharm works simply superb.

Here is a pattern; the http command is HTTPie, a Python based mostly utility:

% http google.com

http: error: gaierror: [Errno 8] nodename nor servname supplied, or not identified
Couldn’t resolve the given hostname. Please test the URL and check out once more.

% python3
Python 3.12.6 (foremost, Sep  6 2024, 19:03:47) [Clang 16.0.0 (clang-1600.0.26.3)] on darwin
Sort "assist", "copyright", "credit" or "license" for extra data.
>>> import socket
>>> socket.getaddrinfo('google.com', 80)
Traceback (most up-to-date name final):
  File "", line 1, in 
  File "/decide/homebrew/Cellar/[email protected]/3.12.6/Frameworks/Python.framework/Variations/3.12/lib/python3.12/socket.py", line 976, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, household, sort, proto, flags):
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
socket.gaierror: [Errno 8] nodename nor servname supplied, or not identified
>>> ^D

% curl google.com

...

% dig google.com
...
;; ANSWER SECTION:
google.com.     41  IN  A   142.250.184.206

;; Question time: 14 msec
;; SERVER: 192.168.178.1#53(192.168.178.1)
;; WHEN: Fri Oct 04 10:13:02 CEST 2024
;; MSG SIZE  rcvd: 55

% http -v 142.250.184.206
GET / HTTP/1.1
Settle for: */*
Settle for-Encoding: gzip, deflate
Connection: keep-alive
Host: 142.250.184.206
Person-Agent: HTTPie/3.2.3



HTTP/1.1 301 Moved Completely
...

As you may see, community connections on the whole are superb, solely DNS queries cannot be resolved. They day trip after about 30 seconds. Nevertheless, the identical inside PyCharm works superb.

I’ve examine HTTP_PROXY setting variables perhaps being an issue, however I haven’t got these set.

I do not know sufficient about DNS decision and the way Python makes use of it to even know the place to look. Any concepts?

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles