Friday, November 8, 2024

macos – Python on Terminal can not 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 not resolve any DNS queries. Nonetheless, the Python console and the builtin Terminal in PyCharm works simply high-quality.

This is a pattern; the http command is HTTPie, a Python primarily based utility:

% http google.com

http: error: gaierror: [Errno 8] nodename nor servname supplied, or not recognized
Couldn’t resolve the given hostname. Please test the URL and take a look at 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 info.
>>> import socket
>>> socket.getaddrinfo('google.com', 80)
Traceback (most up-to-date name final):
  File "<stdin>", line 1, in <module>
  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 recognized
>>> ^D

% curl google.com
<HTML><HEAD><meta http-equiv="content-type" content material="textual content/html;charset=utf-8">
...

% 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’ll be able to see, community connections usually are high-quality, solely DNS queries cannot be resolved. They outing after about 30 seconds. Nonetheless, the identical inside PyCharm works high-quality.

I’ve examine HTTP_PROXY surroundings variables possibly 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