pogzyb / asyncwhois

Python WHOIS and RDAP utility for querying and parsing information about Domains, IPv4s, IPv6s, and AS numbers
MIT License
63 stars 18 forks source link

Unexpected exception for parsing domain #63

Closed Yama85 closed 1 year ago

Yama85 commented 1 year ago

Network request worked successfully, however response processing failed with the following error:

Traceback (most recent call last):

File "asd.py", line 6, in main response = await asyncwhois.aio_rdap_domain('clientservices.scenber.com')

File "C:\Users\SAMPLE_USER\AppData\Local\Programs\Python\Python311\Lib\site-packages\asyncwhois__init__.py", line 93, in aio_rdap_domain result = await DomainLookup.aio_rdap_domain(domain, httpx_client)

File "C:\Users\SAMPLE_USER\AppData\Local\Programs\Python\Python311\Lib\site-packages\asyncwhois\pywhois.py", line 156, in aio_rdap_domain whois_dict = response.to_whois_dict()

File "C:\Users\SAMPLE_USER\AppData\Local\Programs\Python\Python311\Lib\site-packages\whodap\response.py", line 190, in to_whois_dict flat.update(self._flat_entities(self.entities))

File "C:\Users\SAMPLE_USER\AppData\Local\Programs\Python\Python311\Lib\site-packages\whodap\response.py", line 238, in _flat_entities vcard_type = vcard[0]

TypeError: 'DomainResponse' object is not subscriptable

pogzyb commented 1 year ago

Hey thanks for opening an issue and providing context around the exception.

It looks like the response from this registrar, ownregister.com, ownregistrar.com (edit), is not correctly implemented/not RDAP conformant.

Correct vcard array format (https://www.rfc-editor.org/rfc/rfc7483#section-5.1): image

What is implemented here: image

What it should be: image

Additionally, this response has a case where "entities" is not an array, but an object: image

image

Unfortunately, there's not much I can do besides file an RDAP conformance ticket with the registrar.

However, it would be reasonable to expect that this library should more gracefully handle situations like these. Although it's a losing battle to handle interpreting and parsing bad responses. @Yama85 From a user's perspective, do you have any preference on how the to_whois_dict method should behave when it encounters misformatted data? Maybe it would be a good improvement to not "fail" (raise an exception) and instead set a flag somewhere about the rdap conformance problem? Let me know.

pogzyb commented 1 year ago

There's new release of whodap that handles these scenarios.