[GH-ISSUE #268] getting json decoding errors? #205

Closed
opened 2026-02-27 22:08:36 +03:00 by kerem · 3 comments
Owner

Originally created by @shijithpk on GitHub (Apr 8, 2022).
Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/268

Just wanted to let you know I'm getting some json decoding errors with ytmusicapi. Am I doing something wrong somewhere?

So this was the code I wrote:

from ytmusicapi import YTMusic
ytmusic = YTMusic('creds_headers/headers_ytmusic.json')
results = ytmusic.search('oasis morning glory', filter='albums')
results

This is the complete error message i got:

---------------------------------------------------------------------------
JSONDecodeError                           Traceback (most recent call last)
<ipython-input-5-b7b876af8f27> in <module>
      2 ytmusic = YTMusic('creds_headers/headers_ytmusic.json')
      3 
----> 4 results = ytmusic.search('oasis morning glory', filter='albums')
      6 results

~/.local/lib/python3.8/site-packages/ytmusicapi/mixins/browsing.py in search(self, query, filter, scope, limit, ignore_spelling)
    250             body['params'] = params
    251 
--> 252         response = self._send_request(endpoint, body)
    253 
    254         # no results

~/.local/lib/python3.8/site-packages/ytmusicapi/ytmusic.py in _send_request(self, endpoint, body, additionalParams)
    135                                       headers=self.headers,
    136                                       proxies=self.proxies)
--> 137         response_text = json.loads(response.text)
    138         if response.status_code >= 400:
    139             message = "Server returned HTTP " + str(

/usr/lib/python3.8/json/__init__.py in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    355             parse_int is None and parse_float is None and
    356             parse_constant is None and object_pairs_hook is None and not kw):
--> 357         return _default_decoder.decode(s)
    358     if cls is None:
    359         cls = JSONDecoder

/usr/lib/python3.8/json/decoder.py in decode(self, s, _w)
    335 
    336         """
--> 337         obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    338         end = _w(s, end).end()
    339         if end != len(s):

/usr/lib/python3.8/json/decoder.py in raw_decode(self, s, idx)
    353             obj, end = self.scan_once(s, idx)
    354         except StopIteration as err:
--> 355             raise JSONDecodeError("Expecting value", s, err.value) from None
    356         return obj, end

JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Originally created by @shijithpk on GitHub (Apr 8, 2022). Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/268 Just wanted to let you know I'm getting some json decoding errors with ytmusicapi. Am I doing something wrong somewhere? So this was the code I wrote: ``` from ytmusicapi import YTMusic ytmusic = YTMusic('creds_headers/headers_ytmusic.json') results = ytmusic.search('oasis morning glory', filter='albums') results ``` This is the complete error message i got: ``` --------------------------------------------------------------------------- JSONDecodeError Traceback (most recent call last) <ipython-input-5-b7b876af8f27> in <module> 2 ytmusic = YTMusic('creds_headers/headers_ytmusic.json') 3 ----> 4 results = ytmusic.search('oasis morning glory', filter='albums') 6 results ~/.local/lib/python3.8/site-packages/ytmusicapi/mixins/browsing.py in search(self, query, filter, scope, limit, ignore_spelling) 250 body['params'] = params 251 --> 252 response = self._send_request(endpoint, body) 253 254 # no results ~/.local/lib/python3.8/site-packages/ytmusicapi/ytmusic.py in _send_request(self, endpoint, body, additionalParams) 135 headers=self.headers, 136 proxies=self.proxies) --> 137 response_text = json.loads(response.text) 138 if response.status_code >= 400: 139 message = "Server returned HTTP " + str( /usr/lib/python3.8/json/__init__.py in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw) 355 parse_int is None and parse_float is None and 356 parse_constant is None and object_pairs_hook is None and not kw): --> 357 return _default_decoder.decode(s) 358 if cls is None: 359 cls = JSONDecoder /usr/lib/python3.8/json/decoder.py in decode(self, s, _w) 335 336 """ --> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end()) 338 end = _w(s, end).end() 339 if end != len(s): /usr/lib/python3.8/json/decoder.py in raw_decode(self, s, idx) 353 obj, end = self.scan_once(s, idx) 354 except StopIteration as err: --> 355 raise JSONDecodeError("Expecting value", s, err.value) from None 356 return obj, end JSONDecodeError: Expecting value: line 1 column 1 (char 0) ```
kerem closed this issue 2026-02-27 22:08:36 +03:00
Author
Owner

@sigma67 commented on GitHub (Apr 8, 2022):

It seems the server returned an error which was not JSON. I suspect it has something to do with your credentials. Does the search query work fine if you create the YTMusic instance without the headers parameter?

<!-- gh-comment-id:1092596416 --> @sigma67 commented on GitHub (Apr 8, 2022): It seems the server returned an error which was not JSON. I suspect it has something to do with your credentials. Does the search query work fine if you create the YTMusic instance without the headers parameter?
Author
Owner

@shijithpk commented on GitHub (Apr 8, 2022):

Sorry, just saw this, thanks for responding. You're right! I ran the code below unauthenticated and I did get a json response!

from ytmusicapi import YTMusic
ytmusic = YTMusic()
results = ytmusic.search('oasis morning glory', filter='albums')
results

Partial view of the json response

[{'category': 'Albums',
  'resultType': 'album',
  'title': "(What's The Story) Morning Glory? (Remastered)",
  'type': 'Album',
  'duration': None,
  'year': '1995',
  'artists': [{'name': 'Oasis', 'id': 'UCmMUZbaYdNH0bEd1PAlAqsA'}],
  'browseId': 'MPREb_9nqEki4ZDpp',
...

Do you have any idea on what could be wrong with my credentials? Have pasted mine below with some fields XXed out. I'm thinking I should just copy over the headers again and start over. Or is there anything else you think i should do?

{
	"accept": "*/*",
	"accept-encoding": "gzip, deflate, br",
	"accept-language": "en-US,en;q=0.9,en-GB;q=0.8,ml;q=0.7",
	"authorization": "XXXX",
	"content-length": "2021",
	"content-type": "application/json",
	"cookie": "XXX",
	"origin": "https://music.youtube.com",
	"referer": "https://music.youtube.com/",
	"sec-ch-ua": "' Not A;Brand';v='99', 'Chromium';v='100', 'Google Chrome';v='100'",
	"sec-ch-ua-arch": "x86",
	"sec-ch-ua-bitness": "64",
	"sec-ch-ua-full-version": "100.0.4896.60",
	"sec-ch-ua-full-version-list": "' Not A;Brand';v='99.0.0.0', 'Chromium';v='100.0.4896.60', 'Google Chrome';v='100.0.4896.60'",
	"sec-ch-ua-mobile": "?0",
	"sec-ch-ua-platform": "Linux",
	"sec-ch-ua-platform-version": "5.4.0",
	"sec-fetch-dest": "empty",
	"sec-fetch-mode": "same-origin",
	"sec-fetch-site": "same-origin",
	"user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.60 Safari/537.36",
	"x-client-data": "XXXXX",
	"x-goog-authuser": "0",
	"x-goog-visitor-id": "XXXXX",
	"x-origin": "https://music.youtube.com",
	"x-youtube-client-name": "67",
	"x-youtube-client-version": "1.20220328.01.00"
}
<!-- gh-comment-id:1092641511 --> @shijithpk commented on GitHub (Apr 8, 2022): Sorry, just saw this, thanks for responding. You're right! I ran the code below unauthenticated and I did get a json response! ``` from ytmusicapi import YTMusic ytmusic = YTMusic() results = ytmusic.search('oasis morning glory', filter='albums') results ``` Partial view of the json response ``` [{'category': 'Albums', 'resultType': 'album', 'title': "(What's The Story) Morning Glory? (Remastered)", 'type': 'Album', 'duration': None, 'year': '1995', 'artists': [{'name': 'Oasis', 'id': 'UCmMUZbaYdNH0bEd1PAlAqsA'}], 'browseId': 'MPREb_9nqEki4ZDpp', ... ``` Do you have any idea on what could be wrong with my credentials? Have pasted mine below with some fields XXed out. I'm thinking I should just copy over the headers again and start over. Or is there anything else you think i should do? ``` { "accept": "*/*", "accept-encoding": "gzip, deflate, br", "accept-language": "en-US,en;q=0.9,en-GB;q=0.8,ml;q=0.7", "authorization": "XXXX", "content-length": "2021", "content-type": "application/json", "cookie": "XXX", "origin": "https://music.youtube.com", "referer": "https://music.youtube.com/", "sec-ch-ua": "' Not A;Brand';v='99', 'Chromium';v='100', 'Google Chrome';v='100'", "sec-ch-ua-arch": "x86", "sec-ch-ua-bitness": "64", "sec-ch-ua-full-version": "100.0.4896.60", "sec-ch-ua-full-version-list": "' Not A;Brand';v='99.0.0.0', 'Chromium';v='100.0.4896.60', 'Google Chrome';v='100.0.4896.60'", "sec-ch-ua-mobile": "?0", "sec-ch-ua-platform": "Linux", "sec-ch-ua-platform-version": "5.4.0", "sec-fetch-dest": "empty", "sec-fetch-mode": "same-origin", "sec-fetch-site": "same-origin", "user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.60 Safari/537.36", "x-client-data": "XXXXX", "x-goog-authuser": "0", "x-goog-visitor-id": "XXXXX", "x-origin": "https://music.youtube.com", "x-youtube-client-name": "67", "x-youtube-client-version": "1.20220328.01.00" } ```
Author
Owner

@shijithpk commented on GitHub (Apr 9, 2022):

Oh, just to close the issue, i copied over the headers again from my Chrome Developer Tools, and authenticated requests are working again now. Thanks for your help! :)

<!-- gh-comment-id:1093748410 --> @shijithpk commented on GitHub (Apr 9, 2022): Oh, just to close the issue, i copied over the headers again from my Chrome Developer Tools, and authenticated requests are working again now. Thanks for your help! :)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ytmusicapi#205
No description provided.