diff --git a/farmbot/functions/api.py b/farmbot/functions/api.py index b541a41..7870206 100644 --- a/farmbot/functions/api.py +++ b/farmbot/functions/api.py @@ -127,7 +127,7 @@ def request_handling(self, response, make_request): try: response.json() - except requests.exceptions.JSONDecodeError: + except (json.JSONDecodeError, requests.exceptions.RequestException): self.state.error += f" ({text})" else: self.state.error += f" ({json.dumps(response.json(), indent=2)})" diff --git a/farmbot/functions/broker.py b/farmbot/functions/broker.py index 58c3efb..857e2ee 100644 --- a/farmbot/functions/broker.py +++ b/farmbot/functions/broker.py @@ -241,7 +241,7 @@ def wrapper(self, *args, **kwargs): self.stop_listen() return wrapper - @stop_listen_upon_interrupt + @stop_listen_upon_interrupt.__func__ def listen(self, channel="#", duration=None, diff --git a/farmbot/main.py b/farmbot/main.py index f86b801..c2765ed 100644 --- a/farmbot/main.py +++ b/farmbot/main.py @@ -15,7 +15,7 @@ from .functions.resources import Resources from .functions.tools import ToolControls -VERSION = "2.0.4" +VERSION = "2.0.5" class Farmbot(): diff --git a/pyproject.toml b/pyproject.toml index 665da2a..a3662d0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ authors = [ keywords = ["farmbot"] description = "FarmBot Python package" readme = "README.md" -requires-python = ">=3.8" +requires-python = ">=3.9" classifiers = [ "Programming Language :: Python :: 3", "License :: OSI Approved :: MIT License", diff --git a/tests/tests_main.py b/tests/tests_main.py index f801635..c3acfcc 100644 --- a/tests/tests_main.py +++ b/tests/tests_main.py @@ -2,6 +2,7 @@ Farmbot class unit tests. ''' +import sys import json import unittest from unittest.mock import Mock, patch, call @@ -39,6 +40,10 @@ } +JSONDecodeError = requests.exceptions.JSONDecodeError if sys.version_info >= ( + 3, 10) else json.JSONDecodeError + + class TestFarmbot(unittest.TestCase): '''Farmbot tests''' @@ -223,8 +228,7 @@ def test_api_string_error_response_handling(self, mock_request): mock_response.status_code = 404 mock_response.reason = 'reason' mock_response.text = 'error string' - mock_response.json.side_effect = requests.exceptions.JSONDecodeError( - '', '', 0) + mock_response.json.side_effect = JSONDecodeError('', '', 0) mock_request.return_value = mock_response response = self.fb.api_get('device') mock_request.assert_called_once_with( @@ -243,8 +247,7 @@ def test_api_string_error_response_handling_html(self, mock_request): mock_response.status_code = 404 mock_response.reason = 'reason' mock_response.text = '