Set 2s timeout when connecting to Spotify

I've been having an issue where the script hangs for a long time
when starting up. It seems to be caused by the connection request
to Spotify failing on the first request (which uses IPv6) and
having to wait for the retry attempt using IPv4

2s should be plenty for just getting the refresh token and is
much more tolerable in case of IPv6 failure
This commit is contained in:
Tim Rae
2024-05-20 19:36:07 +02:00
parent 8884ec8c8f
commit 1a2aedf7a5

View File

@@ -16,7 +16,8 @@ def open_spotify_session(config) -> spotipy.Spotify:
scope='playlist-read-private',
client_id=config['client_id'],
client_secret=config['client_secret'],
redirect_uri=config['redirect_uri'])
redirect_uri=config['redirect_uri'],
requests_timeout=2)
try:
credentials_manager.get_access_token(as_dict=False)
except spotipy.SpotifyOauthError: