Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WhoisDomainNotFoundError and WhoisUnknownDateFormatError #267

Merged
merged 2 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 13 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
Goal
====
# Goal

- Create a simple importable Python module which will produce parsed
WHOIS data for a given domain.
- Able to extract data for all the popular TLDs (com, org, net, ...)
- Query a WHOIS server directly instead of going through an
intermediate web service like many others do.
- Create a simple importable Python module which will produce parsed
WHOIS data for a given domain.
- Able to extract data for all the popular TLDs (com, org, net, ...)
- Query a WHOIS server directly instead of going through an
intermediate web service like many others do.


Example
=======
# Example

```python
>>> import whois
Expand All @@ -21,7 +18,7 @@ u'\nDomain Name: EXAMPLE.COM
Registry Domain ID: 2336799_DOMAIN_COM-VRSN
...'

>>> print(w) # print values of all found attributes
>>> print(w) # print values of all found attributes
{
"creation_date": "1995-08-14 04:00:00",
"expiration_date": "2022-08-13 04:00:00",
Expand All @@ -34,8 +31,7 @@ Registry Domain ID: 2336799_DOMAIN_COM-VRSN
...
```

Install
=======
# Install

Install from pypi:

Expand All @@ -56,12 +52,11 @@ Run test cases:
python -m pytest
```

Problems?
=========
# Problems?

Pull requests are welcome!
Pull requests are welcome!

Thanks to the many who have sent patches for additional TLDs. If you want to add or fix a TLD it's quite straightforward.
Thanks to the many who have sent patches for additional TLDs. If you want to add or fix a TLD it's quite straightforward.
See example domains in [whois/parser.py](https://github.com/richardpenman/whois/blob/master/whois/parser.py)

Basically each TLD has a similar format to the following:
Expand All @@ -79,7 +74,7 @@ class WhoisOrg(WhoisEntry):

def __init__(self, domain, text):
if text.strip() == 'NOT FOUND':
raise PywhoisError(text)
raise WhoisDomainNotFoundError(text)
else:
WhoisEntry.__init__(self, domain, text)
```
2 changes: 1 addition & 1 deletion test/samples/expected/abv.bg
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"domain_name": "abv.bg", "expiration_date": "see at www.register.bg", "updated_date": null, "registrar": null, "registrar_url": null, "creation_date": null, "status": "Registered"}
{"domain_name": "abv.bg", "expiration_date": null, "updated_date": null, "registrar": null, "registrar_url": null, "creation_date": null, "status": "Registered"}
2 changes: 1 addition & 1 deletion test/samples/expected/google.cl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"domain_name": "google.cl", "expiration_date": "2019-11-20 14:48:02 CLST", "updated_date": null, "registrar": "MarkMonitor Inc.", "registrar_url": "https://markmonitor.com/", "creation_date": "2002-10-22 17:48:23 CLST", "status": null}
{"domain_name": "google.cl", "expiration_date": "2019-11-20 14:48:02", "updated_date": null, "registrar": "MarkMonitor Inc.", "registrar_url": "https://markmonitor.com/", "creation_date": "2002-10-22 17:48:23", "status": null}
2 changes: 1 addition & 1 deletion test/samples/expected/google.com.ua
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"domain_name": "google.com.ua", "expiration_date": "2019-12-04 00:00:00+02", "updated_date": "2018-11-02 11:29:08+02", "registrar": "MarkMonitor Inc.", "registrar_url": "http://markmonitor.com", "creation_date": ["2002-12-04 00:00:00+02", "2017-07-28 23:53:31+03"], "status": ["clientDeleteProhibited", "clientTransferProhibited", "clientUpdateProhibited", "ok", "linked"]}
{"domain_name": "google.com.ua", "expiration_date": "2019-12-04 00:00:00+02:00", "updated_date": "2018-11-02 11:29:08+02:00", "registrar": "MarkMonitor Inc.", "registrar_url": "http://markmonitor.com", "creation_date": ["2002-12-04 00:00:00+02:00", "2017-07-28 23:53:31+03:00"], "status": ["clientDeleteProhibited", "clientTransferProhibited", "clientUpdateProhibited", "ok", "linked"]}
6 changes: 4 additions & 2 deletions whois/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import subprocess
import sys
from typing import Any, Optional, Pattern
from .parser import WhoisEntry, PywhoisError

from .exceptions import WhoisError
from .parser import WhoisEntry
from .whois import NICClient


Expand Down Expand Up @@ -65,7 +67,7 @@ def whois(
whois_command.append(executable_opts)
r = subprocess.Popen(whois_command, stdout=subprocess.PIPE)
if r.stdout is None:
raise PywhoisError("Whois command returned no output")
raise WhoisError("Whois command returned no output")
else:
text = r.stdout.read().decode()
else:
Expand Down
30 changes: 30 additions & 0 deletions whois/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class PywhoisError(Exception):
pass

#backwards compatibility
class WhoisError(PywhoisError):
pass


class UnknownTldError(WhoisError):
pass


class WhoisDomainNotFoundError(WhoisError):
pass


class FailedParsingWhoisOutputError(WhoisError):
pass


class WhoisQuotaExceededError(WhoisError):
pass


class WhoisUnknownDateFormatError(WhoisError):
pass


class WhoisCommandFailedError(WhoisError):
pass
Loading
Loading