Jupyter_contrib_nbextensions: json.decoder.JSONDecodeError

Created on 28 Jan 2018  Â·  8Comments  Â·  Source: ipython-contrib/jupyter_contrib_nbextensions

When I executed jupyter nbextension list I get below error

```python traceback
Known nbextensions:
Traceback (most recent call last):
File "/home/marxlp/anaconda3/bin/jupyter-nbextension", line 11, in
sys.exit(main())
File "/home/marxlp/anaconda3/lib/python3.5/site-packages/jupyter_core/application.py", line 266, in lae
return super(JupyterApp, cls).launch_instance(argv=argv, *kwargs)
File "/home/marxlp/anaconda3/lib/python3.5/site-packages/traitlets/config/application.py", line 658, ie
app.start()
File "/home/marxlp/anaconda3/lib/python3.5/site-packages/notebook/nbextensions.py", line 988, in start
super(NBExtensionApp, self).start()
File "/home/marxlp/anaconda3/lib/python3.5/site-packages/jupyter_core/application.py", line 255, in stt
self.subapp.start()
File "/home/marxlp/anaconda3/lib/python3.5/site-packages/notebook/nbextensions.py", line 960, in start
self.list_nbextensions()
File "/home/marxlp/anaconda3/lib/python3.5/site-packages/notebook/nbextensions.py", line 943, in list_s
data = cm.get(section)
File "/home/marxlp/anaconda3/lib/python3.5/site-packages/notebook/config_manager.py", line 85, in get
recursive_update(data, json.load(f))
File "/home/marxlp/anaconda3/lib/python3.5/json/__init__.py", line 268, in load
parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, *
kw)
File "/home/marxlp/anaconda3/lib/python3.5/json/__init__.py", line 319, in loads
return _default_decoder.decode(s)
File "/home/marxlp/anaconda3/lib/python3.5/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/home/marxlp/anaconda3/lib/python3.5/json/decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 9 column 22 (char 279)

At the same time, when I started jupyter, almost same error appeared,

[E 21:59:54.563 NotebookApp] Uncaught exception GET /api/config/notebook?_=1517147994320 (127.0.0.1)
HTTPServerRequest(protocol='http', host='localhost:8888', method='GET', uri='/api/config/notebook?_=1517147994320', version='HTTP/1.1', remote_ip='127.0.0.1', headers={'X-Requested-With': 'XMLHttpRequest', 'X-Xsrftoken': '2|bd47d974|3c4dc694b7b2d96299ebd2e626afe8f8|1517147993', 'Cookie': 'username-localhost-8888="2|1:0|10:1517147993|23:username-localhost-8888|44:MGZhMjU2ODQzZjAwNDBlMTk0YmJmOWJiYTQ0MGRlZDA=|169f35d60a658c56672b08f30d2a40519f193b1f41cd316e3f5cdce5f0996cd0"; _xsrf=2|bd47d974|3c4dc694b7b2d96299ebd2e626afe8f8|1517147993', 'Connection': 'keep-alive', 'Referer': 'http://localhost:8888/notebooks/test_torch_functions.ipynb', 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:59.0) Gecko/20100101 Firefox/59.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': 'application/json, text/javascript, /; q=0.01', 'Accept-Language': 'en-US,en;q=0.5', 'Host': 'localhost:8888'})
Traceback (most recent call last):
File "/home/marxlp/anaconda3/lib/python3.5/site-packages/tornado/web.py", line 1510, in _execute
result = method(self.path_args, *self.path_kwargs)
File "/home/marxlp/anaconda3/lib/python3.5/site-packages/tornado/web.py", line 2898, in wrapper
return method(self, args, *kwargs)
File "/home/marxlp/anaconda3/lib/python3.5/site-packages/notebook/services/config/handlers.py", line 19, in get
self.finish(json.dumps(self.config_manager.get(section_name)))
File "/home/marxlp/anaconda3/lib/python3.5/site-packages/notebook/services/config/manager.py", line 25, in get
recursive_update(config, cm.get(section_name))
File "/home/marxlp/anaconda3/lib/python3.5/site-packages/notebook/config_manager.py", line 85, in get
recursive_update(data, json.load(f))
File "/home/marxlp/anaconda3/lib/python3.5/json/__init__.py", line 268, in load
parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
File "/home/marxlp/anaconda3/lib/python3.5/json/__init__.py", line 319, in loads
return _default_decoder.decode(s)
File "/home/marxlp/anaconda3/lib/python3.5/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/home/marxlp/anaconda3/lib/python3.5/json/decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 9 column 22 (char 279)
```
I have tried reinstall jupyter and nbextensions. But it didn't work.

Most helpful comment

It looks like you have a corrupted JSON config file. What happens if you try this short Python snipper:

import glob
import os
import json
from jupyter_core.paths import jupyter_config_path

for d in jupyter_config_path():
    for p in glob.glob(os.path.join(d, 'nbconfig', '*.json')):
        try:
            with open(p, 'r') as f:
                json.load(f)
            print('File {0} is OK.'.format(p))
        except json.decoder.JSONDecodeError:
            print('Failed JSON file is:', p)

All 8 comments

It looks like you have a corrupted JSON config file. What happens if you try this short Python snipper:

import glob
import os
import json
from jupyter_core.paths import jupyter_config_path

for d in jupyter_config_path():
    for p in glob.glob(os.path.join(d, 'nbconfig', '*.json')):
        try:
            with open(p, 'r') as f:
                json.load(f)
            print('File {0} is OK.'.format(p))
        except json.decoder.JSONDecodeError:
            print('Failed JSON file is:', p)

Here are the returns,

Failed JSON file is: /home/marxlp/.jupyter/nbconfig/notebook.json
File /home/marxlp/.jupyter/nbconfig/edit.json is OK.
File /home/marxlp/.jupyter/nbconfig/common.json is OK.
File /home/marxlp/.jupyter/nbconfig/tree.json is OK.
File /home/marxlp/anaconda3/etc/jupyter/nbconfig/notebook.json is OK.
File /home/marxlp/anaconda3/etc/jupyter/nbconfig/tree.json is OK.

The content of notebook.json are

{
  "load_extensions": {
    "jupyter-notebook-gist/extension": true,
    "jupyter-js-widgets/extension": true,
    "nbextensions_configurator/config_menu/main": true,
    "contrib_nbextensions_help_item/main": true,
    "equation-numbering/main": true
  },

  "oauth_client_id":

I delete the last line and the line configure the jupyter-notebook-gist, and It worked. The command jupyter nbextension list worked correctly. Thank you very much. :smile:
But the error still here when jupyter starts. Maybe it's authentication failed?. I don't know why~

This looks like a duplicate of #1192, which is caused by a bug in the jupyter-notebook-gist extension, see the issue at https://github.com/mozilla/jupyter-notebook-gist/issues/56, which tries to rewrite the config file each time the noteobok server starts, but manages to corrupt the json file :frowning_face:

Thanks for your advice. :blush:

The erro like this
File "/home/charle/New_Begining/crawler/cq315house/cq315house_New.py", line 201, in Get_MyData_112 data = json.loads(data, encoding='utf-8') File "/home/charle/anaconda3/lib/python3.6/json/__init__.py", line 354, in loads return _default_decoder.decode(s) File "/home/charle/anaconda3/lib/python3.6/json/decoder.py", line 339, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/home/charle/anaconda3/lib/python3.6/json/decoder.py", line 355, in raw_decode obj, end = self.scan_once(s, idx) json.decoder.JSONDecodeError: Expecting ',' delimiter: line 1 column 116 (char 115)
My data like this:
{'__dataType':'1' ,'CERT':'isql="1"'},
when I replace the quote " ‘ " to the " " ",
The quote " " " lead to this erro.

Hi, I know this is closed, but a modification helped me get to my solution. I expanded @juhasch's snippet into something slightly more robust and found that I had pydeck.json causing an issue.

(And, believe me, I've been working on this for a while. I'm still not sure I'll even have IPython widgets enabled, which was the objective of this exercise in the first place! But, at least I'm not getting a "500 Internal Error" message now.)

Updated code:

import glob
import os
import json
from jupyter_core.paths import jupyter_config_path

def check_all():
    for folder in jupyter_config_path():
        for root, _, files in os.walk(folder):
            for f in files:
                if f.endswith("json"):
                    json_pth = os.path.join(root, f)
                    try:
                        with open(json_pth, 'r') as f:
                            json.load(f)
                        print(f"File {json_pth} is OK.")
                    except json.decoder.JSONDecodeError:
                        print('Failed JSON file is: ', json_pth)


if __name__ == "__main__":
    check_all()

Terminal output:

image

Was this page helpful?
0 / 5 - 0 ratings

Related issues

slowkow picture slowkow  Â·  3Comments

Time1ess picture Time1ess  Â·  7Comments

gaskamichal picture gaskamichal  Â·  5Comments

ggrrll picture ggrrll  Â·  6Comments

Hgh2017 picture Hgh2017  Â·  3Comments