whois
whois copied to clipboard
socket.gaierror: [Errno -2] Name or service not known on multiple TLDs
I'm receiving 'socket.gaierror: [Errno -2] Name or service not known' on multiple TLDs, but not every domain within the TLDs.
For example, webkit.org: `
import whois whois.whois('webkit.org') Traceback (most recent call last): File "
", line 1, in File "/usr/local/lib/python3.7/dist-packages/whois/init.py", line 40, in whois text = nic_client.whois_lookup(None, domain.encode('idna'), 0) File "/usr/local/lib/python3.7/dist-packages/whois/whois.py", line 204, in whois_lookup result = self.whois(query_arg, nichost, flags) File "/usr/local/lib/python3.7/dist-packages/whois/whois.py", line 145, in whois response += self.whois(query, nhost, 0) File "/usr/local/lib/python3.7/dist-packages/whois/whois.py", line 114, in whois s.connect((hostname, 43)) socket.gaierror: [Errno -2] Name or service not known `
Not every .org though, because google.org works fine, as does a non-existent .org domain.
I've also noticed this on some .com.mx domains, for example test.com.mx: `
whois.whois('test.com.mx') Traceback (most recent call last): File "
", line 1, in File "/usr/local/lib/python3.7/dist-packages/whois/init.py", line 40, in whois text = nic_client.whois_lookup(None, domain.encode('idna'), 0) File "/usr/local/lib/python3.7/dist-packages/whois/whois.py", line 204, in whois_lookup result = self.whois(query_arg, nichost, flags) File "/usr/local/lib/python3.7/dist-packages/whois/whois.py", line 114, in whois s.connect((hostname, 43)) socket.gaierror: [Errno -2] Name or service not known `
I've tried this on multiple different machines and VMs and receive consistent results. I'm using Python3 and Linux kernel 4.15.
Confirmed - also fails for me with webkit.org and works for google.org.
I have submitted a fix in the latest commit - does this work for you?
I just downloaded the latest commit and I'm having the same issue.
$ python -m whois 01.org
Traceback (most recent call last):
File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/mark/Documents/project/lib/python3.6/site-packages/whois/whois.py", line 343, in
But the whois binary works fine on the same machine so it isn't actually name resolution causing the problem.
$ whois 01.org
Domain Name: 01.ORG
Registry Domain ID: D762704-LROR
Registrar WHOIS Server: whois.cscglobal.com
Registrar URL: www.cscglobal.com/global/web/csc/digital-brand
Updated Date: 2018-11-30T19:51:44Z
Creation Date: 1998-01-15T05:00:00Z
Registry Expiry Date: 2027-01-14T05:00:00Z
Registrar Registration Expiration Date:
Registrar: CSC Corporate Domains, Inc.
I tried to debug the issue and I can see that the org.whois-servers.net returns the host whois.cscglobal.net as the registar. But that hostname doesn't seem to exist. This seems more like errors in the whois server records than an error in the code. In my mind the question becomes how is the whois binary working and what is it doing that is different because it is able to retrieve the record. Thanks for your help. Mark
hmm perhaps the registrar servers have changed: https://github.com/richardpenman/whois/blob/master/whois/whois.py#L48
I don't know if something changed since then but I'm currently unable to reproduce when using the most recent commit
https://stackoverflow.com/questions/73324691/whois-data-for-country-level-domains-like-co-in-com-sg-etc mentions the same problem for co.in
and com.sg
domains. I can trivially repro with whois.whois("google.com.sg")
, though the error message I see is slightly different.
>>> import whois
>>> w = whois.whois("google.com.sg")
Error trying to connect to socket: closing socket - [Errno 8] nodename nor servname provided, or not known
This might be fixed now:
➜ python3
Python 3.12.3 (main, Apr 9 2024, 08:09:14) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import whois
>>> whois.whois("google.com.sg")
{'domain_name': 'google.com.sg', 'registrant_name': None, 'registrar': 'MarkMonitor Inc.', 'creation_date': datetime.datetime(2002, 7, 5, 9, 42, 32), 'expiration_date': datetime.datetime(2025, 7, 4, 16, 0), 'dnssec': None}
Great!