Skip to content

Commit

Permalink
Merge pull request #35 from pogzyb/catch-jsondecodeerrors
Browse files Browse the repository at this point in the history
Catch JSONDecodeError
  • Loading branch information
pogzyb committed Nov 4, 2023
2 parents 664c26a + 190a905 commit 5bfad93
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions whodap/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import ipaddress
from typing import Dict, Any, Union, Optional, List
from contextlib import contextmanager
from json import JSONDecodeError

# different installs for async contextmanager based on python version
if sys.version_info < (3, 7):
Expand Down Expand Up @@ -198,7 +199,13 @@ def _get_authoritative_response(
# save href chain
self.rdap_hrefs.append(href)
# check for more authoritative source
rdap_json = resp.json()
try:
# If for some reason the response is invalid json, then just return None.
# This may happen if we request an authoritative href that is not actually
# rdap+json, but instead a webpage/html.
rdap_json = resp.json()
except JSONDecodeError:
return None
links = rdap_json.get("links")
if links:
next_href = self._check_next_href(href, links)
Expand Down Expand Up @@ -231,7 +238,13 @@ async def _aio_get_authoritative_response(
raise
# save href chain
self.rdap_hrefs.append(href)
rdap_json = resp.json()
try:
# If for some reason the response is invalid json, then just return None.
# This may happen if we request an authoritative href that is not actually
# rdap+json, but instead a webpage/html.
rdap_json = resp.json()
except JSONDecodeError:
return None
links = rdap_json.get("links")
if links:
next_href = self._check_next_href(href, links)
Expand Down

0 comments on commit 5bfad93

Please sign in to comment.