Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix infinite authorization errors #346

Merged
merged 1 commit into from
Nov 5, 2023
Merged
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
8 changes: 5 additions & 3 deletions asusrouter/asusrouter.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ async def async_api_load(
self,
endpoint: Endpoint | EndpointControl,
request: str = "",
retry: bool = False,
retry: int = 0,
) -> dict[str, Any]:
"""Load API endpoint with optional request."""

Expand All @@ -263,8 +263,10 @@ async def async_api_load(
# Check whether we are not connected
args = ex.args
if args[1] == AccessError.AUTHORIZATION:
# Reconnect
await self.async_connect()
# Mark the connection as dropped
await self._async_drop_connection()
# Wait before repeating the request
await asyncio.sleep(1 + retry * 3)
# Repeat request once more and see what happens
return await self.async_api_load(endpoint, request, True)
# Otherwise just raise the exception
Expand Down
10 changes: 0 additions & 10 deletions asusrouter/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,6 @@ async def async_connect(
)
_LOGGER.debug("Received authorization response")
except AsusRouterAccessError as ex:
# Check the AccessError
if ex.args[1] == AccessError.TRY_AGAIN:
# Get the timeout
timeout = ex.args[2].get("timeout") + 5
if timeout:
_LOGGER.debug("Will try again in %s seconds", timeout)
await asyncio.sleep(timeout)
return await self.async_connect(retry, asyncio.Lock())
raise ex
# In case of any other error, switch to the next except block
raise ex
except AsusRouterError as ex:
_LOGGER.debug("Connection failed")
Expand Down