Skip to content

Commit

Permalink
Merge pull request #267 from Misiu/more-errors
Browse files Browse the repository at this point in the history
WhoisDomainNotFoundError and WhoisUnknownDateFormatError
  • Loading branch information
richardpenman authored Jan 27, 2025
2 parents bf707ae + 1aae233 commit b3e0122
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 132 deletions.
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

0 comments on commit b3e0122

Please sign in to comment.