Skip to content
Open
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
9 changes: 5 additions & 4 deletions eodhd/APIs/BaseAPI.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from json.decoder import JSONDecodeError
import sys
from requests import get as requests_get
from requests import ConnectionError as requests_ConnectionError
from requests import Timeout as requests_Timeout
from requests.exceptions import HTTPError as requests_HTTPError
from requests.exceptions import HTTPError as requests_HTTPError, JSONDecodeError as requests_JSONDecodeError
from rich.console import Console

class BaseAPI:
Expand All @@ -24,7 +23,9 @@ def _rest_get_method(self, api_key: str, endpoint: str = "", uri: str = "", quer

if resp.status_code != 200:
try:
if "message" in resp.json():
if resp.headers.get("Content-Type") != 'application/json':
resp_message = resp.text
elif "message" in resp.json():
resp_message = resp.json()["message"]
elif "errors" in resp.json():
self.console.log(resp.json())
Expand All @@ -35,7 +36,7 @@ def _rest_get_method(self, api_key: str, endpoint: str = "", uri: str = "", quer
message = f"({resp.status_code}) {self._api_url} - {resp_message}"
self.console.log(message)

except JSONDecodeError as err:
except requests_JSONDecodeError as err:
self.console.log(err)

try:
Expand Down
9 changes: 5 additions & 4 deletions eodhd/apiclient.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""apiclient.py"""

from json.decoder import JSONDecodeError
import sys
from enum import Enum
from datetime import datetime
Expand All @@ -11,7 +10,7 @@
from requests import get as requests_get
from requests import ConnectionError as requests_ConnectionError
from requests import Timeout as requests_Timeout
from requests.exceptions import HTTPError as requests_HTTPError
from requests.exceptions import HTTPError as requests_HTTPError, JSONDecodeError as requests_JSONDecodeError
from rich.console import Console
from rich.progress import track

Expand Down Expand Up @@ -119,7 +118,9 @@ def _rest_get(self, endpoint: str = "", uri: str = "", querystring: str = "") ->

if resp.status_code != 200:
try:
if "message" in resp.json():
if resp.headers.get("Content-Type") != 'application/json':
resp_message = resp.text
elif "message" in resp.json():
resp_message = resp.json()["message"]
elif "errors" in resp.json():
self.console.log(resp.json())
Expand All @@ -130,7 +131,7 @@ def _rest_get(self, endpoint: str = "", uri: str = "", querystring: str = "") ->
message = f"({resp.status_code}) {self._api_url} - {resp_message}"
self.console.log(message)

except JSONDecodeError as err:
except requests_JSONDecodeError as err:
self.console.log(err)

try:
Expand Down