Skip to content

Commit fb2a544

Browse files
committed
Protect against KeyError in get_playlists
Not all implementations return the internal 'playlist' key with an empty array, some omit the key entirely. Protect against raising a KeyError by checking presence. Signed-off-by: Eric B Munson <eric@munsonfam.org>
1 parent c947110 commit fb2a544

3 files changed

Lines changed: 11 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
##7.0.4
2+
3+
Check for 'playlist' item inside 'playlists' when invoking get_playlists end point. Not all servers
4+
include an empty array and some omit the internal key entirely. Protect against raising a KeyError
5+
by checking for presence.
6+
17
##7.0.3
28

39
Remove insecure flag from Connection object. This was vestigial from the Requests library refactor

src/libopensonic/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717

1818

1919
#Semantic versioning string for the library
20-
__version__ = '7.0.3'
20+
__version__ = '7.0.4'

src/libopensonic/connection.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,10 @@ def get_playlists(self, username:str|None=None) -> list[Playlist]:
12711271
res = self._do_request(method, q)
12721272
dres = self._handle_info_res(res)
12731273
self._check_status(dres)
1274-
return [Playlist.from_dict(entry) for entry in dres['playlists']['playlist']]
1274+
if 'playlist' in dres['playlists']:
1275+
return [Playlist.from_dict(entry) for entry in dres['playlists']['playlist']]
1276+
else:
1277+
return []
12751278

12761279

12771280
def get_play_queue(self) -> PlayQueue:

0 commit comments

Comments
 (0)