ledesmablt / spotify-cli

Control Spotify playback on any device through the command line.
MIT License
113 stars 15 forks source link

AttributeError: 'NoneType' object has no attribute 'get' #20

Open hooliowobbits opened 3 years ago

hooliowobbits commented 3 years ago
$ spotify seek 0
Traceback (most recent call last):
  File "/home/hoolio/.local/bin/spotify", line 8, in <module>
    sys.exit(cli())
  File "/usr/lib/python3/dist-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3/dist-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3/dist-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3/dist-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/hoolio/.local/lib/python3.8/site-packages/cli/commands/seek.py", line 41, in seek
    duration_ms = status_data.get('item').get('duration_ms')
AttributeError: 'NoneType' object has no attribute 'get'

I get this on two machines, both of which were working yesterday. A Spotify API change?

hooliowobbits commented 3 years ago

ah! it just started working

$ spotify seek 0
Position set to 0s

..what's going on there do you think?

ledesmablt commented 3 years ago

possible that the API returned incomplete data - item key had no value, so it was evaluated as None.get('duration_ms')

not sure why this would happen since when you try running spotify seek 0 with no song playing, it shows an error message (no playback session detected) instead of that traceback.

hooliowobbits commented 3 years ago

Hi mate, I may have closed this issue too early; this was happening again this morning.

ledesmablt commented 3 years ago

I'll try to keep testing this to see what's going wrong, though I can't seem to replicate it on my end. What device are you playing spotify from?

hooliowobbits commented 3 years ago

well, i have several.. ;) but the ones exhibiting the issue are both 20.04 with the python dependencies locally installed using system python 3. It feels like an API issue. I wonder in that instance if there was anything in the API return? perhaps a verbose mode might help

ledesmablt commented 3 years ago

Hmm I really can't seem to replicate the issue on my end, so I configured the cli to save the last response of every API request (excluding token refresh) to ~/.config/last-response.json in v0.3.11. Hopefully this will help you with debugging.

The API must have returned something since some error handling is set up, but **the response might have been incomplete. Strange that this only happens sometimes.