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

SpotifyClient.play()/pause() raising JsonDecodeError #22

Closed
starry-shivam opened this issue Aug 1, 2021 · 4 comments
Closed

SpotifyClient.play()/pause() raising JsonDecodeError #22

starry-shivam opened this issue Aug 1, 2021 · 4 comments

Comments

@starry-shivam
Copy link
Contributor

I'm getting simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0) everytime i call SpotifyClient.play/pause() though they indeed work but the error after that is unexpected, right now I'm just doing

try:
   SpotifyClient.play()
except ValueError:
   pass

But i really hope this gets fixed soon, was also getting JsonDecodeError on some other methods aswell like SpotifyClient.currently_playing() if I'm not playing any track, i would rather hope for it to raise ApiError or just return None in that case instead of raising JsonDecodeError.

Traceback

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/simplejson/scanner.py", line 37, in _scan_once
    nextchar = string[idx]
IndexError: string index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 6, in <module>
  File "/home/ubuntu/.local/lib/python3.9/site-packages/pyfy/wrappers.py", line 142, in sync_wrapper
    return self._send_authorized_request(request).json()
  File "/usr/lib/python3/dist-packages/requests/models.py", line 897, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/lib/python3/dist-packages/simplejson/__init__.py", line 518, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
  File "/usr/lib/python3/dist-packages/simplejson/scanner.py", line 79, in scan_once
    return _scan_once(string, idx)
  File "/usr/lib/python3/dist-packages/simplejson/scanner.py", line 39, in _scan_once
    raise JSONDecodeError(errmsg, string, idx)
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)```
@starry-shivam
Copy link
Contributor Author

I think it's happening here cause the error it's trying to catch is incorrect, as we can see in traceback it's raised by simplejson and error is simplejson.errors.JSONDecodeError but here
it's getting imported from python's std lib json module. I think it should catch simplejson's JsonDecodeError or just catch ValueError as all JsonDecodeErrors are subclasses of ValueError.

@omarryhan
Copy link
Owner

As far as I remember, some methods such as play and pause returned empty responses when successful. So when we try to JSON decode them they raise an error.

You're probably right, JsonDecodeError is probably an overkill. I'll change it now and release a new version.

Thanks for filing this issue!

@starry-shivam
Copy link
Contributor Author

Thanks!

@omarryhan
Copy link
Owner

No problem :)
Fixed in v2.0.9

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

No branches or pull requests

2 participants