From b071b85836b5102716b6aab7e8ab1e13e597972d Mon Sep 17 00:00:00 2001 From: sdb9696 Date: Thu, 22 Feb 2024 09:33:15 +0000 Subject: [PATCH] Retry query on 403 after succesful handshake --- kasa/klaptransport.py | 4 ++-- kasa/tests/test_klapprotocol.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/kasa/klaptransport.py b/kasa/klaptransport.py index ab33ca18e..8feae98c1 100644 --- a/kasa/klaptransport.py +++ b/kasa/klaptransport.py @@ -57,7 +57,7 @@ from .credentials import Credentials from .deviceconfig import DeviceConfig -from .exceptions import AuthenticationError, KasaException +from .exceptions import AuthenticationError, KasaException, _RetryableError from .httpclient import HttpClient from .json import loads as json_loads from .protocol import DEFAULT_CREDENTIALS, BaseTransport, get_default_credentials, md5 @@ -337,7 +337,7 @@ async def send(self, request: str): # If we failed with a security error, force a new handshake next time. if response_status == 403: self._handshake_done = False - raise AuthenticationError( + raise _RetryableError( f"Got a security error from {self._host} after handshake " + "completed" ) diff --git a/kasa/tests/test_klapprotocol.py b/kasa/tests/test_klapprotocol.py index 7c8054758..b71ea460d 100644 --- a/kasa/tests/test_klapprotocol.py +++ b/kasa/tests/test_klapprotocol.py @@ -417,7 +417,7 @@ async def _return_response(url: URL, params=None, data=None, *_, **__): pytest.param( (200, 200, 403), True, - pytest.raises(AuthenticationError), + pytest.raises(_RetryableError), id="request-403-status", ), pytest.param(