Jupyter Notebook运行服务器列表 - ValueError:无法解码JSON对象

时间:2018-06-07 14:03:48

标签: python jupyter-notebook

我想使用命令行获取正在运行的服务器列表:

jupyter notebook list

我收到错误:

Traceback (most recent call last):
  File "/home/sarah/anaconda3/envs/py27/bin/jupyter-notebook", line 11, in <module>
    sys.exit(main())
  File "/home/sarah/anaconda3/envs/py27/lib/python2.7/site-packages/jupyter_core/application.py", line 266, in launch_instance
    return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
  File "/home/sarah/anaconda3/envs/py27/lib/python2.7/site-packages/traitlets/config/application.py", line 658, in launch_instance
    app.start()
  File "/home/sarah/anaconda3/envs/py27/lib/python2.7/site-packages/notebook/notebookapp.py", line 1571, in start
    super(NotebookApp, self).start()
  File "/home/sarah/anaconda3/envs/py27/lib/python2.7/site-packages/jupyter_core/application.py", line 255, in start
    self.subapp.start()
  File "/home/sarah/anaconda3/envs/py27/lib/python2.7/site-packages/notebook/notebookapp.py", line 483, in start
    serverinfo_list = list(list_running_servers(self.runtime_dir))
  File "/home/sarah/anaconda3/envs/py27/lib/python2.7/site-packages/notebook/notebookapp.py", line 1667, in list_running_servers
    info = json.load(f)
  File "/home/sarah/anaconda3/envs/py27/lib/python2.7/json/__init__.py", line 291, in load
    **kw)
  File "/home/sarah/anaconda3/envs/py27/lib/python2.7/json/__init__.py", line 339, in loads
    return _default_decoder.decode(s)
  File "/home/sarah/anaconda3/envs/py27/lib/python2.7/json/decoder.py", line 364, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/home/sarah/anaconda3/envs/py27/lib/python2.7/json/decoder.py", line 382, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

如何纠正?我不明白原因。

1 个答案:

答案 0 :(得分:1)

确定运行中的笔记本服务器的逻辑依赖于对运行时目录中所有带有前缀“ nbserver-”的文件进行迭代,然后尝试以JSON格式加载。因此,此文件夹中格式错误的文件可能会导致JSON错误。通过删除Jupyter runtime-dir下的所有文件来解决此问题:

$ jupyter --runtime-dir
/home/user/.local/share/jupyter/runtime
$ cd $(jupyter --runtime-dir) && rm *