Fix Meebook JWT token expiry: invalidate cached token and retry#1
Merged
Conversation
…onses When the Meebook API returns a JSON string instead of a JSON array (e.g., after token expiration), json.loads() returns a Python string. Iterating over a string gives individual characters, causing TypeError: string indices must be integers on person["name"]. Changes: - Meebook: Wrap json.loads in try/except, validate data is a list before iterating, preserve exceptionMessage handling for dict responses - Huskelisten: Fix incomplete exception handling (set data=None on failure), validate data is a list before iterating - Use specific exception types instead of bare except Co-authored-by: Jogge <15981279+Jogge@users.noreply.github.com>
Co-authored-by: Jogge <15981279+Jogge@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix intermittent failure in Home Assistant custom integration
Fix TypeError when Meebook/Huskelisten APIs return non-list JSON responses
Mar 20, 2026
…piry response
When Meebook API returns {'message': 'JWT-Token expired, please renew.'},
clear the cached token for widget 0004 and retry the request once with a
fresh token. This allows automatic recovery without requiring a restart.
Co-authored-by: Jogge <15981279+Jogge@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Jogge/aula/sessions/28528ad2-5ca5-4520-af27-45d36d02646e
Copilot
AI
changed the title
Fix TypeError when Meebook/Huskelisten APIs return non-list JSON responses
Fix Meebook JWT token expiry: invalidate cached token and retry
Mar 24, 2026
When Meebook returns 'JWT-Token expired', the widget token cache was cleared and a new widget token was fetched from aulaToken.getAulaToken. But the Aula session access token itself was stale, so the new widget token was also expired by Meebook. Fix: Call self.login() to refresh the Aula session before getting a new widget token. This ensures aulaToken.getAulaToken generates a valid token from a fresh session. The login call is wrapped in try/except to handle gracefully if refresh fails. Co-authored-by: Jogge <15981279+Jogge@users.noreply.github.com> Agent-Logs-Url: https://github.com/Jogge/aula/sessions/92e87394-bf32-4707-bfbe-748281ed7a1f
When Meebook says "JWT-Token expired", login() was called but it saw the Aula access token was still valid and reused it. This meant aulaToken.getAulaToken generated widget tokens from the same session, which Meebook still rejected. Fix: Add force_refresh parameter to login() that skips the "reuse valid token" shortcut and proceeds directly to renew_access_token(). The Meebook retry path now calls login(force_refresh=True) to ensure the Aula access token is actually renewed before fetching a new widget token. Co-authored-by: Jogge <15981279+Jogge@users.noreply.github.com> Agent-Logs-Url: https://github.com/Jogge/aula/sessions/e60de5ef-ca34-4f82-a0fb-6c3ee8e86c5f
When Meebook returns "JWT-Token expired", the retry refreshed the OAuth access token but kept the same requests.Session() with stale Aula server-side session cookies. The aulaToken.getAulaToken endpoint then returned a Meebook JWT that was already expired because the stale cookies pointed to an expired server-side session. Fix: Reset self._session = None before login retry, so _apply_token_to_session() creates a fresh requests.Session() with no stale cookies. This matches the behavior on HA restart (which works). Agent-Logs-Url: https://github.com/Jogge/aula/sessions/b0d0263c-0500-481f-9a22-4622ba526a9e Co-authored-by: Jogge <15981279+Jogge@users.noreply.github.com>
Review confirmed all client.py changes are necessary: - login(force_refresh) for Meebook retry flow - Session reset + token refresh on Meebook JWT expiry - Defensive JSON parsing (try/except, type guards) - Huskelisten bare except narrowed + data=None on failure Agent-Logs-Url: https://github.com/Jogge/aula/sessions/594a9cd8-54e4-451c-aa38-86ea03600994 Co-authored-by: Jogge <15981279+Jogge@users.noreply.github.com>
Jogge
approved these changes
Apr 6, 2026
Jogge
approved these changes
Apr 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
tests/test_client_response_handling.py(owner requested removal)client.pychanges are necessary📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.