HelloZeroNet / ZeroNet

ZeroNet - Decentralized websites using Bitcoin crypto and BitTorrent network
https://zeronet.io
Other
18.37k stars 2.27k forks source link

The error "ValueError: No JSON object could be decoded" should say what the object is #1080

Open yurivict opened 7 years ago

yurivict commented 7 years ago

Is it an invalid file, or something received from the network? Which site does it relate to?

Currently, the error is:

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/gevent/greenlet.py", line 536, in run
    result = self._run(*self.args, **self.kwargs)
  File "/usr/local/share/zeronet/src/Site/Site.py", line 402, in update
    file_info = self.content_manager.getFileInfo(bad_file)
  File "/usr/local/share/zeronet/src/Content/ContentManager.py", line 319, in getFileInfo
    content = self.contents.get(content_inner_path.strip("/"))
  File "/usr/local/share/zeronet/src/Content/ContentDbDict.py", line 105, in get
    return self.__getitem__(key)
  File "/usr/local/share/zeronet/src/Content/ContentDbDict.py", line 55, in __getitem__
    return self.loadItem(key)
  File "/usr/local/share/zeronet/src/Content/ContentDbDict.py", line 23, in loadItem
    content = self.site.storage.loadJson(key)
  File "/usr/local/share/zeronet/src/Site/SiteStorage.py", line 254, in loadJson
    return json.load(file)
  File "/usr/local/lib/python2.7/json/__init__.py", line 291, in load
    **kw)
  File "/usr/local/lib/python2.7/json/__init__.py", line 339, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python2.7/json/decoder.py", line 364, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/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
Slaviusz commented 7 years ago

I have lots of these. I believe it prevents me to download some pages like ZeroMail (5 file update failed) and GIFTime (2 file update failed).

[12:44:33] Site:1TaLkF..jipT data/users/1NtsBLNSXtBuFg52FbWGD9gQJJaXKQKG5F/content.json: verify sign error: ValueError: No JSON object could be decoded in ContentManager.py line 804 > __init__.py line 291 > __init__.py line 339 > decoder.py line 364 > decoder.py line 382
[12:44:46] Site:1TaLkF..jipT data/users/16bxMyoL49mWYhcZKBYVBT5zEFW9SQpiao/content.json: verify sign error: ValueError: Extra data: line 1 column 2 - line 19 column 2 (char 1 - 718) in ContentManager.py line 804 > __init__.py line 291 > __init__.py line 339 > decoder.py line 367
[12:45:16] Site:1TaLkF..jipT data/users/1MDVhLhAhbw5NchZiHCZ9aooU1KtqZdQY5/content.json: verify sign error: ValueError: No JSON object could be decoded in ContentManager.py line 804 > __init__.py line 291 > __init__.py line 339 > decoder.py line 364 > decoder.py line 382
[12:45:17] Site:1TaLkF..jipT data/users/1NtUxUGV3r3htk4rMM172YMkBscb1tekFF/content.json: verify sign error: ValueError: No JSON object could be decoded in ContentManager.py line 804 > __init__.py line 291 > __init__.py line 339 > decoder.py line 364 > decoder.py line 382

Info:

[13:01:32] - OpenSSL loaded, version: 0100020CF
[13:01:32] - Version: 0.6.0 r3106, Python 2.7.12 (default, Sep 13 2017, 22:06:49) 
[GCC 4.9.3], Gevent: 1.2.1
[13:01:32] - Creating FileServer....
[13:01:32] TorManager Connecting to Tor Controller 127.0.0.1:9051
[13:01:32] - Creating UiServer....
[13:01:32] - Removing old SSL certs...
[13:01:32] - Starting servers....
[13:01:32] Ui.UiServer --------------------------------------
[13:01:32] Ui.UiServer Web interface: http://127.0.0.1:43110/
[13:01:32] Ui.UiServer --------------------------------------
yurivict commented 6 years ago

This bug is still present.

It just says "[15:14:29] - Unhandled exception: No JSON object could be decoded". How can I find a bad json?

HelloZeroNet commented 6 years ago

Can you please paste the full error? There should be more information after that line (or in log/error.log)

yurivict commented 6 years ago
[15:30:49] SiteManager Loading sites...
[15:30:49] - Unhandled exception: No JSON object could be decoded
Traceback (most recent call last):
  File "/usr/local/share/zeronet/zeronet.py", line 19, in main
    main.start()
  File "/usr/local/share/zeronet/src/main.py", line 509, in start
    actions.call(config.action, action_kwargs)
  File "/usr/local/share/zeronet/src/main.py", line 157, in call
    func(**kwargs)
  File "/usr/local/share/zeronet/src/main.py", line 167, in main
    ui_server = UiServer()
  File "/usr/local/share/zeronet/src/Ui/UiServer.py", line 75, in __init__
    self.sites = SiteManager.site_manager.list()
  File "/usr/local/share/zeronet/src/Site/SiteManager.py", line 170, in list
    self.load(startup=True)
  File "plugins/Zeroname/SiteManagerPlugin.py", line 20, in load
    super(SiteManagerPlugin, self).load(*args, **kwargs)
  File "plugins/MergerSite/MergerSitePlugin.py", line 377, in load
    super(SiteManagerPlugin, self).load(*args, **kwags)
  File "plugins/Chart/ChartPlugin.py", line 21, in load
    back = super(SiteManagerPlugin, self).load(*args, **kwargs)
  File "/usr/local/share/zeronet/src/Site/SiteManager.py", line 35, in load
    for address, settings in json.load(open("%s/sites.json" % config.data_dir)).iteritems():
  File "/usr/local/lib/python2.7/json/__init__.py", line 291, in load
    **kw)
  File "/usr/local/lib/python2.7/json/__init__.py", line 339, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python2.7/json/decoder.py", line 364, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/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
[15:30:49] - Unhandled exception
None
- Starting ZeroNet...
Traceback (most recent call last):
  File "/usr/local/share/zeronet/zeronet.py", line 91, in <module>
    main()
  File "/usr/local/share/zeronet/zeronet.py", line 64, in main
    traceback.print_exc(file=open(config.log_dir + "/error.log", "a"))
AttributeError: 'Config' object has no attribute 'log_dir'
[15:30:49] SiteManager Save skipped: No sites found
HelloZeroNet commented 6 years ago

The problem is with data/sites.json file, please check the content and there could be sites.json-old as backup

yurivict commented 6 years ago

sites.json is empty. There is sites.json-tmpnew which is valid.

purplesyringa commented 6 years ago

Rename sites.json-tmpnew to sites.json. This probably happened because ZeroNet didn't shutdown gracefully.

AFAIK ZeroNet uses a feature called atomicWrite, so I'm not sure why sites.json is empty. (@HelloZeroNet correct me if I'm wrong)

HelloZeroNet commented 6 years ago

Yes it should not happen, here is the function: https://github.com/HelloZeroNet/ZeroNet/blob/master/src/util/helper.py#L15

So it works this way:

So I don't really see the possibility to have a valid site.json-tmpnew and an empty sites.json