pythonjupyter-notebookanacondajupyterjupyter-lab

Jupyter Lab throws "json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)" from workspaces handler


I'm on Windows. Have been using Jupyter Lab for a while with no problems. Very recently, every time I launched Jupyter, it errored out as such:

[W 2024-09-08 02:02:06.730 ServerApp] 500 GET /lab/api/workspaces?1725750126696 (::1): Expecting value: line 1 column 1 (char 0)
[W 2024-09-08 02:02:06.731 LabApp] wrote error: 'Expecting value: line 1 column 1 (char 0)'

With the following traceback:

Traceback (most recent call last):
      File "C:\Users\user_name\anaconda3\envs\env_name\lib\site-packages\jupyterlab_server\workspaces_handler.py", line 198, in get
        workspaces = self.manager.list_workspaces()
      File "C:\Users\user_name\anaconda3\envs\env_name\lib\site-packages\jupyterlab_server\workspaces_handler.py", line 125, in list_workspaces
        return _list_workspaces(self.workspaces_dir, prefix)
      File "C:\Users\user_name\anaconda3\envs\env_name\lib\site-packages\jupyterlab_server\workspaces_handler.py", line 46, in _list_workspaces
        workspace = _load_with_file_times(workspace_path)
      File "C:\Users\user_name\anaconda3\envs\env_name\lib\site-packages\jupyterlab_server\workspaces_handler.py", line 59, in _load_with_file_times
        workspace = json.load(fid)
      File "C:\Users\user_name\anaconda3\envs\env_name\lib\json\__init__.py", line 293, in load
        return loads(fp.read(),
      File "C:\Users\user_name\anaconda3\envs\env_name\lib\json\__init__.py", line 357, in loads
        return _default_decoder.decode(s)
      File "C:\Users\user_name\anaconda3\envs\env_name\lib\json\decoder.py", line 337, in decode
        obj, end = self.raw_decode(s, idx=_w(s, 0).end())
      File "C:\Users\user_name\anaconda3\envs\env_name\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)

After this point, I can load notebooks and run code blocks, but the changes don't save (and only the first run's output is displayed: further runs do not affect the output even if the code is modified and a different output is expected).

The workspaces list (under the "Running Terminals and Kernels" tab) appears to be empty. If relevant, this all occurs within an Anaconda virtual environment.

How might this be fixed?


Solution

  • Seems like one of the workspace files was somehow corrupted. The fix eventually was to stop Jupyter Lab, remove the C:\Users\user_name\.jupyter\lab\workspaces directory, and re-launch. A new workspace was created after this point and everything seemed to work fine.


    Do note that this probably deletes workspace settings, so preferably back the directory up somewhere instead of outright deleting it if you have any such settings you don't want to lose.

    Also note that I'm new to Jupyter and am not sure if this path is guaranteed to follow this exact structure in all environments. I found it by editing the workspaces_handler.py file mentioned above that threw this exception and printing the workspace_path mentioned there, right before line 46 mentioned in the traceback (and then undoing that change after grabbing the path).
    If needed, this process can be repeated to find the workspaces directory (although I'm sure there are much neater ways to find it that don't involve a look at Jupyter source, such as looking at Jupyter docs instead :-) This was just a quick fix I'd attempted and it worked).