JSONDecodeError when Musixmatch provider get 404 http status code
qwertyadrian opened this issue · 0 comments
qwertyadrian commented
I get the following error
Traceback (most recent call last):
File "/home/qwertyadrian/PycharmProjects/pyscripts/lyrics/lyrics.py", line 114, in <module>
lrc = provider.get_lrc(query)
^^^^^^^^^^^^^^^^^^^^^^^
File "/home/qwertyadrian/PycharmProjects/pyscripts/venv/lib/python3.11/site-packages/syncedlyrics/providers/musixmatch.py", line 25, in get_lrc
body = r.json()["message"]["body"]
^^^^^^^^
File "/usr/lib/python3.11/site-packages/requests/models.py", line 975, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
when I use Musixmatch provider and get 404 http status code.
Code to reproduce the error (for example):
from syncedlyrics.providers import Musixmatch
provider = Musixmatch()
lrc = provider.get_lrc('(muscle museum) #2 - Muse')
My solution:
--- syncedlyrics/providers/musixmatch.py 2023-06-10 19:42:23.258790255 +0300
+++ syncedlyrics/providers/musixmatch_fixed.py 2023-06-10 19:42:56.178241855 +0300
@@ -22,6 +22,8 @@
def get_lrc(self, search_term: str) -> Optional[str]:
url = self.SEARCH_ENDPOINT.format(q=search_term, token=self.USER_TOKEN)
r = self.session.get(url)
+ if r.status_code != 200:
+ return
body = r.json()["message"]["body"]
if not body:
# 401 - captcha