Fix Pandora authentication failures#2949
Merged
MarvinSchenkel merged 11 commits intodevfrom Jan 26, 2026
Merged
Conversation
Implemented automatic re-authentication mechanism for Pandora provider to prevent auth token expiry during extended listening sessions. - Added token expiration tracking with AUTH_TOKEN_LIFETIME (50 minutes) - Added ensure_valid_auth() method to proactively re-authenticate before token expiration (with 5 minute buffer) - Updated _api_request() to call ensure_valid_auth() before all API calls - Added retry logic for 401 errors to handle reactive re-authentication This follows the same pattern used by the Tidal provider for maintaining valid authentication tokens during long-running sessions. Fixes issue where users reported authentication expiring while listening to Pandora stations.
Updated authentication to check if Pandora returns expiry information (expiresIn or expires_in fields) and use it if available, rather than always assuming a hardcoded lifetime. - Checks for expiry fields in authentication response - Uses actual expiry if provided by API - Falls back to conservative 50-minute estimate if not - Added logging to show which approach is being used This makes the implementation more robust and will automatically adapt if Pandora provides expiry information in their response.
Changed from proactive time-based re-authentication to reactive 401-error handling only. This is a better approach because: 1. User reports show auth failures occurring anywhere from 5 minutes to several hours, indicating it's NOT a simple token timeout 2. Proactive re-auth would mask the real issue and prevent diagnosis 3. Reactive handling will log actual failure patterns to help identify the root cause (concurrent logins, IP changes, rate limiting, etc.) Changes: - Removed AUTH_TOKEN_LIFETIME and AUTH_REFRESH_BUFFER constants - Removed ensure_valid_auth() proactive check method - Removed _auth_expires_at expiry tracking - Added _auth_time to track when authentication occurred - Enhanced 401 error handling to log how long tokens lasted - Simplified to reactive-only approach: retry on 401 with fresh auth This will help diagnose the actual cause of auth expiry issues while still preventing playback interruption by automatically re-authenticating when needed.
Changed authentication success and token expiry messages from info/warning to debug level to reduce log noise for routine operations.
Removed _auth_time tracking and associated debug logging that calculated token lifetime. Fix is confirmed working, diagnostic code no longer needed.
Added ProviderUnavailableError handling to _handle_stream_request to prevent crashes when network errors (DNS timeouts, connection failures) occur during fragment fetching. - Wrapped all _get_fragment_data calls in try-except block - Added ProviderUnavailableError exception handler - Returns 503 Service Unavailable instead of crashing - Logs error for diagnostics
Refactored _api_request to use recursive call instead of duplicating error handling code in retry block. - Added 'retry: bool = True' parameter to _api_request - On 401 error, re-authenticate and recursively call with retry=False - Eliminates ~20 lines of duplicate error handling code - Cleaner and more maintainable Credit: @MarvinSchenkel for the suggestion
Fixed ruff linting error - removed unnecessary else clause after return statement in retry logic.
MarvinSchenkel
approved these changes
Jan 26, 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.
Fixes music-assistant/support#4731