exislow / tidal-dl-ng

TIDAL Media Downloader Next Generation! Up to HiRes Lossless / TIDAL MAX 24-bit, 192 kHz.
GNU Affero General Public License v3.0
336 stars 30 forks source link

[Bug] Both CLI and GUI app crashes with JSONDecodeError: Expecting value: line 1 column 1 (char 0) #197

Open ViktorVoloshko opened 4 days ago

ViktorVoloshko commented 4 days ago

What happened?

When I try to log in with tidal-dl-ng login or start a GUI version (both installed from pip and downloaded from releases) I get error about some JSON.

I already tried to use this app. Standalone version started but parsing link of oops page failed. I returned to it weeks later and now it fails to start even.

Version App

0.15.6

What operating system are you seeing the problem on?

Windows

Relevant log output

CLI:
╭─────────────────────────────────────────────────────────── Traceback (most recent call last) ────────────────────────────────────────────────────────────╮
│ C:\Users\ViktorVoloshko\tidal-dl-ng\Lib\site-packages\requests\models.py:974 in json                                                                     │
│                                                                                                                                                          │
│    971 │   │   │   │   │   raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)                   ╭───────── locals ──────────╮                            │
│    972 │   │                                                                                    │ kwargs = {}               │                            │
│    973 │   │   try:                                                                             │   self = <Response [403]> │                            │
│ ❱  974 │   │   │   return complexjson.loads(self.text, **kwargs)                                ╰───────────────────────────╯                            │
│    975 │   │   except JSONDecodeError as e:                                                                                                              │
│    976 │   │   │   # Catch JSON-related errors and raise as requests.JSONDecodeError                                                                     │
│    977 │   │   │   # This aliases json.JSONDecodeError and simplejson.JSONDecodeError                                                                    │
│                                                                                                                                                          │
│ C:\Users\ViktorVoloshko\AppData\Local\Programs\Python\Python311\Lib\json\__init__.py:346 in loads                                                        │
│                                                                                                                                                          │
│   343 │   if (cls is None and object_hook is None and                                                                                                    │
│   344 │   │   │   parse_int is None and parse_float is None and                                                                                          │
│   345 │   │   │   parse_constant is None and object_pairs_hook is None and not kw):                                                                      │
│ ❱ 346 │   │   return _default_decoder.decode(s)                                                                                                          │
│   347 │   if cls is None:                                                                                                                                │
│   348 │   │   cls = JSONDecoder                                                                                                                          │
│   349 │   if object_hook is not None:                                                                                                                    │
│                                                                                                                                                          │
│ ╭────────────────────────────────────────────────── locals ──────────────────────────────────────────────────╮                                           │
│ │               cls = None                                                                                   │                                           │
│ │                kw = {}                                                                                     │                                           │
│ │       object_hook = None                                                                                   │                                           │
│ │ object_pairs_hook = None                                                                                   │                                           │
│ │    parse_constant = None                                                                                   │                                           │
│ │       parse_float = None                                                                                   │                                           │
│ │         parse_int = None                                                                                   │                                           │
│ │                 s = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.or'+839 │                                           │
│ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────╯                                           │
│                                                                                                                                                          │
│ C:\Users\ViktorVoloshko\AppData\Local\Programs\Python\Python311\Lib\json\decoder.py:337 in decode                                                        │
│                                                                                                                                                          │
│   334 │   │   containing a JSON document).                                                                                                               │
│   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):                                                                                                                          │
│   340 │   │   │   raise JSONDecodeError("Extra data", s, end)                                                                                            │
│                                                                                                                                                          │
│ ╭─────────────────────────────────────────── locals ────────────────────────────────────────────╮                                                        │
│ │   _w = <built-in method match of re.Pattern object at 0x000001E6FBBDC450>                     │                                                        │
│ │    s = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.or'+839 │                                                        │
│ │ self = <json.decoder.JSONDecoder object at 0x000001E6FBBC7890>                                │                                                        │
│ ╰───────────────────────────────────────────────────────────────────────────────────────────────╯                                                        │
│                                                                                                                                                          │
│ C:\Users\ViktorVoloshko\AppData\Local\Programs\Python\Python311\Lib\json\decoder.py:355 in raw_decode                                                    │
│                                                                                                                                                          │
│   352 │   │   try:                                                                                                                                       │
│   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                                                                                                                            │
│   357                                                                                                                                                    │
│                                                                                                                                                          │
│ ╭─────────────────────────────────────────── locals ────────────────────────────────────────────╮                                                        │
│ │  idx = 0                                                                                      │                                                        │
│ │    s = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.or'+839 │                                                        │
│ │ self = <json.decoder.JSONDecoder object at 0x000001E6FBBC7890>                                │                                                        │
│ ╰───────────────────────────────────────────────────────────────────────────────────────────────╯                                                        │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

╭─────────────────────────────────────────────────────────── Traceback (most recent call last) ────────────────────────────────────────────────────────────╮
│ C:\Users\ViktorVoloshko\tidal-dl-ng\Lib\site-packages\tidal_dl_ng\cli.py:102 in login                                                                    │
│                                                                                                                                                          │
│    99 │   print("Let us check, if you are already logged in... ", end="")                                                                                │
│   100 │                                                                                                                                                  │
│   101 │   settings = Settings()                                                                                                                          │
│ ❱ 102 │   tidal = Tidal(settings)                                                                                                                        │
│   103 │   result = tidal.login(fn_print=print)                                                                                                           │
│   104 │   ctx.obj[CTX_TIDAL] = tidal                                                                                                                     │
│   105                                                                                                                                                    │
│                                                                                                                                                          │
│ ╭─────────────────────────────── locals ────────────────────────────────╮                                                                                │
│ │      ctx = <click.core.Context object at 0x000001E6FA2ACED0>          │                                                                                │
│ │ settings = <tidal_dl_ng.config.Settings object at 0x000001E6FD8BA850> │                                                                                │
│ ╰───────────────────────────────────────────────────────────────────────╯                                                                                │
│                                                                                                                                                          │
│ C:\Users\ViktorVoloshko\tidal-dl-ng\Lib\site-packages\tidal_dl_ng\helper\decorator.py:19 in __call__                                                     │
│                                                                                                                                                          │
│   16 │   │   the returned instance.                                                                                                                      │
│   17 │   │   """                                                                                                                                         │
│   18 │   │   if cls not in cls._instances:                                                                                                               │
│ ❱ 19 │   │   │   instance = super().__call__(*args, **kwargs)                                                                                            │
│   20 │   │   │   cls._instances[cls] = instance                                                                                                          │
│   21 │   │                                                                                                                                               │
│   22 │   │   return cls._instances[cls]                                                                                                                  │
│                                                                                                                                                          │
│ ╭──────────────────────────────── locals ────────────────────────────────╮                                                                               │
│ │   args = (<tidal_dl_ng.config.Settings object at 0x000001E6FD8BA850>,) │                                                                               │
│ │ kwargs = {}                                                            │                                                                               │
│ ╰────────────────────────────────────────────────────────────────────────╯                                                                               │
│                                                                                                                                                          │
│ C:\Users\ViktorVoloshko\tidal-dl-ng\Lib\site-packages\tidal_dl_ng\config.py:101 in __init__                                                              │
│                                                                                                                                                          │
│    98 │   │   # self.session.config.client_secret = "vcmeGW1OuZ0fWYMCSZ6vNvSLJlT3XEpW0ambgYt5Z                                                           │
│    99 │   │   self.file_path = path_file_token()                                                                                                         │
│   100 │   │   self.token_from_storage = self.read(self.file_path)                                                                                        │
│ ❱ 101 │   │   self.login_token()                                                                                                                         │
│   102 │   │                                                                                                                                              │
│   103 │   │   if settings:                                                                                                                               │
│   104 │   │   │   self.settings = settings                                                                                                               │
│                                                                                                                                                          │
│ ╭───────────────────────────────── locals ──────────────────────────────────╮                                                                            │
│ │         self = <tidal_dl_ng.config.Tidal object at 0x000001E6FD876790>    │                                                                            │
│ │     settings = <tidal_dl_ng.config.Settings object at 0x000001E6FD8BA850> │                                                                            │
│ │ tidal_config = <tidalapi.session.Config object at 0x000001E6FD8BA2D0>     │                                                                            │
│ ╰───────────────────────────────────────────────────────────────────────────╯                                                                            │
│                                                                                                                                                          │
│ C:\Users\ViktorVoloshko\tidal-dl-ng\Lib\site-packages\tidal_dl_ng\config.py:127 in login_token                                                           │
│                                                                                                                                                          │
│   124 │   │                                                                                                                                              │
│   125 │   │   if self.token_from_storage:                                                                                                                │
│   126 │   │   │   try:                                                                                                                                   │
│ ❱ 127 │   │   │   │   result = self.session.load_oauth_session(                                                                                          │
│   128 │   │   │   │   │   self.data.token_type,                                                                                                          │
│   129 │   │   │   │   │   self.data.access_token,                                                                                                        │
│   130 │   │   │   │   │   self.data.refresh_token,                                                                                                       │
│                                                                                                                                                          │
│ ╭───────────────────────────── locals ──────────────────────────────╮                                                                                    │
│ │ do_pkce = False                                                   │                                                                                    │
│ │  result = False                                                   │                                                                                    │
│ │    self = <tidal_dl_ng.config.Tidal object at 0x000001E6FD876790> │                                                                                    │
│ ╰───────────────────────────────────────────────────────────────────╯                                                                                    │
│                                                                                                                                                          │
│ C:\Users\ViktorVoloshko\tidal-dl-ng\Lib\site-packages\tidalapi\session.py:403 in load_oauth_session                                                      │
│                                                                                                                                                          │
│    400 │   │   self.expiry_time = expiry_time                                                                                                            │
│    401 │   │   self.is_pkce = is_pkce                                                                                                                    │
│    402 │   │                                                                                                                                             │
│ ❱  403 │   │   request = self.request.request("GET", "sessions")                                                                                         │
│    404 │   │   json = request.json()                                                                                                                     │
│    405 │   │   if not request.ok:                                                                                                                        │
│    406 │   │   │   return False                                                                                                                          │
│                                                                                                                                                          │
│ ╭──────────────────────────────── locals ─────────────────────────────────╮                                                                              │
│ │  access_token = None                                                    │                                                                              │
│ │   expiry_time = 0.0                                                     │                                                                              │
│ │       is_pkce = False                                                   │                                                                              │
│ │ refresh_token = None                                                    │                                                                              │
│ │          self = <tidalapi.session.Session object at 0x000001E6FD8BA250> │                                                                              │
│ │    token_type = None                                                    │                                                                              │
│ ╰─────────────────────────────────────────────────────────────────────────╯                                                                              │
│                                                                                                                                                          │
│ C:\Users\ViktorVoloshko\tidal-dl-ng\Lib\site-packages\tidalapi\request.py:147 in request                                                                 │
│                                                                                                                                                          │
│   144 │   │   │   log.info("Got exception {}".format(e))                                                                                                 │
│   145 │   │   │   log.debug("Response was {}".format(e.response))                                                                                        │
│   146 │   │   │   if request.content:                                                                                                                    │
│ ❱ 147 │   │   │   │   log.debug("response: %s", json.dumps(request.json(), indent=4))                                                                    │
│   148 │   │   │   if request.status_code and request.status_code == 404:                                                                                 │
│   149 │   │   │   │   raise ObjectNotFound                                                                                                               │
│   150 │   │   │   elif request.status_code and request.status_code == 429:                                                                               │
│                                                                                                                                                          │
│ ╭────────────────────────────── locals ──────────────────────────────╮                                                                                   │
│ │    data = None                                                     │                                                                                   │
│ │ headers = None                                                     │                                                                                   │
│ │  method = 'GET'                                                    │                                                                                   │
│ │  params = None                                                     │                                                                                   │
│ │    path = 'sessions'                                               │                                                                                   │
│ │ request = <Response [403]>                                         │                                                                                   │
│ │    self = <tidalapi.request.Requests object at 0x000001E6FD8DA0D0> │                                                                                   │
│ ╰────────────────────────────────────────────────────────────────────╯                                                                                   │
│                                                                                                                                                          │
│ C:\Users\ViktorVoloshko\tidal-dl-ng\Lib\site-packages\requests\models.py:978 in json                                                                     │
│                                                                                                                                                          │
│    975 │   │   except JSONDecodeError as e:                                                     ╭───────── locals ──────────╮                            │
│    976 │   │   │   # Catch JSON-related errors and raise as requests.JSONDecodeError            │ kwargs = {}               │                            │
│    977 │   │   │   # This aliases json.JSONDecodeError and simplejson.JSONDecodeError           │   self = <Response [403]> │                            │
│ ❱  978 │   │   │   raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)                           ╰───────────────────────────╯                            │
│    979 │                                                                                                                                                 │
│    980 │   @property                                                                                                                                     │
│    981 │   def links(self):                                                                                                                              │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Let us check, if you are already logged in...

GUI (pip):
Traceback (most recent call last):
  File "C:\Users\ViktorVoloshko\tidal-dl-ng\Lib\site-packages\requests\models.py", line 974, in json
    return complexjson.loads(self.text, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ViktorVoloshko\AppData\Local\Programs\Python\Python311\Lib\json\__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ViktorVoloshko\AppData\Local\Programs\Python\Python311\Lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ViktorVoloshko\AppData\Local\Programs\Python\Python311\Lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\ViktorVoloshko\tidal-dl-ng\Scripts\tidal-dl-ng-gui.exe\__main__.py", line 7, in <module>
  File "C:\Users\ViktorVoloshko\tidal-dl-ng\Lib\site-packages\tidal_dl_ng\gui.py", line 1033, in gui_activate
    window = MainWindow(tidal=tidal)
             ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ViktorVoloshko\tidal-dl-ng\Lib\site-packages\tidal_dl_ng\gui.py", line 117, in __init__
    self.init_tidal(tidal)
  File "C:\Users\ViktorVoloshko\tidal-dl-ng\Lib\site-packages\tidal_dl_ng\gui.py", line 128, in init_tidal
    self.tidal = Tidal(self.settings)
                 ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ViktorVoloshko\tidal-dl-ng\Lib\site-packages\tidal_dl_ng\helper\decorator.py", line 19, in __call__
    instance = super().__call__(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ViktorVoloshko\tidal-dl-ng\Lib\site-packages\tidal_dl_ng\config.py", line 101, in __init__
    self.login_token()
  File "C:\Users\ViktorVoloshko\tidal-dl-ng\Lib\site-packages\tidal_dl_ng\config.py", line 127, in login_token
    result = self.session.load_oauth_session(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ViktorVoloshko\tidal-dl-ng\Lib\site-packages\tidalapi\session.py", line 403, in load_oauth_session
    request = self.request.request("GET", "sessions")
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ViktorVoloshko\tidal-dl-ng\Lib\site-packages\tidalapi\request.py", line 147, in request
    log.debug("response: %s", json.dumps(request.json(), indent=4))
                                         ^^^^^^^^^^^^^^
  File "C:\Users\ViktorVoloshko\tidal-dl-ng\Lib\site-packages\requests\models.py", line 978, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

GUI (standalone):
Traceback (most recent call last):
  File "requests\models.py", line 974, in json
  File "json\__init__.py", line 346, in loads
  File "json\decoder.py", line 337, in decode
  File "json\decoder.py", line 355, in raw_decode
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "tidal_dl_ng\gui.py", line 1042, in <module>
  File "tidal_dl_ng\gui.py", line 1033, in gui_activate
  File "tidal_dl_ng\gui.py", line 117, in __init__
  File "tidal_dl_ng\gui.py", line 128, in init_tidal
  File "tidal_dl_ng\helper\decorator.py", line 19, in __call__
  File "tidal_dl_ng\config.py", line 101, in __init__
  File "tidal_dl_ng\config.py", line 127, in login_token
  File "tidalapi\session.py", line 403, in load_oauth_session
  File "tidalapi\request.py", line 147, in request
  File "requests\models.py", line 978, in json
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Your settings

{"skip_existing": "False", "lyrics_embed": false, "lyrics_file": false, "video_download": true, "download_delay": true, "download_base_path": "~/download", "quality_audio": "HIGH", "quality_video": "480", "format_album": "Albums/{album_artist} - {album_title}{album_explicit}/{album_track_num}. {artist_name} - {track_title}", "format_playlist": "Playlists/{playlist_name}/{artist_name} - {track_title}", "format_mix": "Mix/{mix_name}/{artist_name} - {track_title}", "format_track": "Tracks/{artist_name} - {track_title}{track_explicit}", "format_video": "Videos/{artist_name} - {track_title}{track_explicit}", "video_convert_mp4": true, "path_binary_ffmpeg": "", "metadata_cover_dimension": "320", "extract_flac": true, "downgrade_on_hi_res": false}
ViktorVoloshko commented 4 days ago

Turns out that if login failed there's still invalid token.json left. You need to delete it before retrying.

%HOMEPATH%\.config\tidal_dl_ng\token.json on Windows.

ViktorVoloshko commented 4 days ago

Actually this should be fixed I think. Just check if JSON is valid (has non-empty fields) and in case it is invalid just treat it as if there's no JSON.