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

'NoneType' object is not subscriptable #7

Closed
rynr opened this issue Sep 9, 2020 · 5 comments · Fixed by #8
Closed

'NoneType' object is not subscriptable #7

rynr opened this issue Sep 9, 2020 · 5 comments · Fixed by #8

Comments

@rynr
Copy link

rynr commented Sep 9, 2020

Within home-assistant, the current status of a jellyfin instance is not updated. The logs show the following:

ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/pyemby/server.py", line 287, in socket_connection
    self.process_msg(msg.data)
  File "/usr/local/lib/python3.8/site-packages/pyemby/server.py", line 319, in process_msg
    self.update_device_list(self._sessions)
  File "/usr/local/lib/python3.8/site-packages/pyemby/server.py", line 342, in update_device_list
    dev_name, device['NowPlayingItem']['Type'],
TypeError: 'NoneType' object is not subscriptable

This looks to me like an issue in pyemby, perhaps just some mapping, or is this an issue by jellyfin not implementing the API correclty?

This has been reported in home-assistant/core#38501

@rynr
Copy link
Author

rynr commented Sep 18, 2020

I asked for help at reddit, will hopefully get some response.

@iwalton3
Copy link

This would be because the Jellyfin serializer started returning null values instead of not including the key in the response. It caused some problems for me too in jellyfin-mpv-shim.

This code would have to be updated to deal with a null value for device['NowPlayingItem'] in addition to the key not being present.

It was changed all over, so more changes for where keys historically weren't present now need to also deal with null values. I've gotten really defensive about null values coming back from Jellyfin accordingly.

@mcarlton00
Copy link
Contributor

iwalton's correct. What's happening is that some of the responses from the server are coming back as None. As an example, here's the device profile I'm getting from Home Assistant.

{'AdditionalUsers': [],
 'ApplicationVersion': '1.6',
 'Capabilities': {'AppStoreUrl': None,
                  'DeviceProfile': None,
                  'IconUrl': None,
                  'MessageCallbackUrl': None,
                  'PlayableMediaTypes': [],
                  'SupportedCommands': [],
                  'SupportsContentUploading': False,
                  'SupportsMediaControl': False,
                  'SupportsPersistentIdentifier': True,
                  'SupportsSync': False},
 'Client': 'Home-Assistant',
 'DeviceId': '229044588395818',
 'DeviceName': 'HomeAssistant',
 'DeviceType': None,
 'FullNowPlayingItem': None,
 'HasCustomDeviceName': False,
 'Id': 'b8a8f09816c76aa04e04dbd3151f4cff',
 'IsActive': True,
 'LastActivityDate': '2020-09-20T16:04:15.3467043Z',
 'LastPlaybackCheckIn': '0001-01-01T00:00:00',
 'NowPlayingItem': None,
 'NowPlayingQueue': None,
 'NowViewingItem': None,
 'PlayState': {'AudioStreamIndex': None,
               'CanSeek': False,
               'IsMuted': False,
               'IsPaused': False,
               'MediaSourceId': None,
               'PlayMethod': None,
               'PositionTicks': None,
               'RepeatMode': 'RepeatNone',
               'SubtitleStreamIndex': None,
               'VolumeLevel': None},
 'PlayableMediaTypes': [],
 'PlaylistItemId': None,
 'RemoteEndPoint': '::ffff:192.168.0.148',
 'ServerId': '0e23a5ed08c84a159ea7d7aea7ff5e67',
 'SupportedCommands': [],
 'SupportsMediaControl': False,
 'SupportsRemoteControl': False,
 'TranscodingInfo': None,
 'UserId': '00000000-0000-0000-0000-000000000000',
 'UserName': None,
 'UserPrimaryImageTag': None}

Relatively easy fix, but then there's several other places in the codebase that are doing similar things where it assumes if the key exists, it will be a dict. For example:

new_theme = new['NowPlayingItem']['IsThemeMedia']
and

pyEmby/pyemby/device.py

Lines 124 to 125 in 6bb621e

artists = self.session['NowPlayingItem']['Artists']
if len(artists) > 1:

I'm working through and trying to find each of them right now, should have a PR up in a bit.

@mcarlton00
Copy link
Contributor

Further update: In it's current state basically every function in device.py that involves the NowPlayingItem needs refactored. eg:

@property
def media_id(self):
    """ Return title currently playing."""
    try:
        return self.session['NowPlayingItem']['Id']
    except KeyError:
        return None

would need to become something along the lines of

@property
def media_id(self):
    """ Return title currently playing."""
    if self.session['NowPlayingItem']:
        return self.session['NowPlayingItem']['Id']
    else:
        return None

Obviously this would be a lot of changes in that file that may not be entirely wanted. An alternative method would be something that we implemented in our Kodi addon that solves the problem by simply removing all keys with values of None. https://github.com/jellyfin/jellyfin-kodi/blob/master/jellyfin_kodi/jellyfin/utils.py

@mezz64 let me know which direction you'd rather go with it.

@mezz64
Copy link
Owner

mezz64 commented Sep 21, 2020

@mcarlton00 I'd prefer the remove None valued keys approach. Seems much more elegant than checking everywhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants