Skip to content
This repository has been archived by the owner on Dec 31, 2024. It is now read-only.

JSON Decode Error #4

Open
helcone opened this issue Apr 5, 2022 · 8 comments
Open

JSON Decode Error #4

helcone opened this issue Apr 5, 2022 · 8 comments
Labels
bug Something isn't working

Comments

@helcone
Copy link

helcone commented Apr 5, 2022

I ran into this issue this week, I saw that :mount command was not running on ranger so I decided to output into a file using sterr and got the following error

  1 Traceback (most recent call last):
  2   File "/home/user/.config/ranger/ranger_udisk_menu/menu.py", line 229, in <module>
  3     cp = ChoosePartition()
  4   File "/home/user/.config/ranger/ranger_udisk_menu/menu.py", line 34, in __init__
  5     self._read_partitions()
  6   File "/home/user/.config/ranger/ranger_udisk_menu/menu.py", line 38, in _read_partitions
  7     self.blkinfo = json.loads(r)
  8   File "/usr/lib/python3.10/json/__init__.py", line 346, in loads
  9     return _default_decoder.decode(s)
 10   File "/usr/lib/python3.10/json/decoder.py", line 337, in decode
 11     obj, end = self.raw_decode(s, idx=_w(s, 0).end())
 12   File "/usr/lib/python3.10/json/decoder.py", line 353, in raw_decode
 13     obj, end = self.scan_once(s, idx)
 14 json.decoder.JSONDecodeError: Expecting ',' delimiter: line 66 column 22 (char 1579)
~

So I decided to check the dependencies listed and I have it installed all of them also I tried to run lsblk --all --json -O and get a good json format. I was wondering if this can be from json.load() function?

@xZeroW
Copy link

xZeroW commented Apr 18, 2022

having the same issue, any luck on this?

edit: running menu.py with a pendrive plugged doesn't show anything, no error but, makes my mouse lag a lot

@ghost
Copy link

ghost commented Apr 27, 2022

Can confirm. Same error, except Line 14 is slightly different. Please lmk if you need more info from me.

json.decoder.JSONDecodeError: Expecting ',' delimiter: line 66 column 22 (char 1687)

@cain-dev
Copy link

I ran into this issue this week, I saw that :mount command was not running on ranger so I decided to output into a file using sterr and got the following error

  1 Traceback (most recent call last):
  2   File "/home/user/.config/ranger/ranger_udisk_menu/menu.py", line 229, in <module>
  3     cp = ChoosePartition()
  4   File "/home/user/.config/ranger/ranger_udisk_menu/menu.py", line 34, in __init__
  5     self._read_partitions()
  6   File "/home/user/.config/ranger/ranger_udisk_menu/menu.py", line 38, in _read_partitions
  7     self.blkinfo = json.loads(r)
  8   File "/usr/lib/python3.10/json/__init__.py", line 346, in loads
  9     return _default_decoder.decode(s)
 10   File "/usr/lib/python3.10/json/decoder.py", line 337, in decode
 11     obj, end = self.raw_decode(s, idx=_w(s, 0).end())
 12   File "/usr/lib/python3.10/json/decoder.py", line 353, in raw_decode
 13     obj, end = self.scan_once(s, idx)
 14 json.decoder.JSONDecodeError: Expecting ',' delimiter: line 66 column 22 (char 1579)
~

So I decided to check the dependencies listed and I have it installed all of them also I tried to run lsblk --all --json -O and get a good json format. I was wondering if this can be from json.load() function?

same error here but (char 1686)

@shervinsahba
Copy link

Traceback (most recent call last):
  File "/home/user/.config/ranger/ranger_udisk_menu/menu.py", line 229, in <module>
    cp = ChoosePartition()
  File "/home/user/.config/ranger/ranger_udisk_menu/menu.py", line 34, in __init__
    self._read_partitions()
  File "/home/user/.config/ranger/ranger_udisk_menu/menu.py", line 38, in _read_partitions
    self.blkinfo = json.loads(r)
  File "/usr/lib/python3.10/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.10/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.10/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting ',' delimiter: line 66 column 22 (char 1633)

Same error, slightly different character (1633). The error persists on different Python versions (tested 3.7, 3.8, 3.10). Is the character referring to the output of lsblk --all --json -O? I went to char 1633 in the output of this command, but it looks like normal json to me.

If I edit out the -O in the menu.py call to lsblk, the two commands in question run fine.

import json; import subprocess
r = subprocess.check_output(['lsblk', '--all', '--json'])
json.loads(r)

However, ranger_udisk_menu relies on some of the information from -O which I've yet to investigate.

@jra419
Copy link
Contributor

jra419 commented May 14, 2022

I also had this issue recently and found a quick and dirty fix.

The JSON output from lsblk seems to have some issues that interfere with the json.loads() function. In my case, also on line 66, column 22, it had to do with 0B not being a string.

"zone-sz": 0B,

By doing a direct replace on the lsblk output for 0B on menu.py, the JSON is parsed and the menu appears.

def _read_partitions(self):
    r = subprocess.check_output(['lsblk', '--all', '--json', '-O'])
    r = r.decode().replace('0B,', '\"0B\",')
    self.blkinfo = json.loads(r.encode())

I've tested it with an external disk and usb drive and it works as expected.

@shervinsahba
Copy link

@Shinkirou Good find! I think this is the fix. Do you want to PR it?

@SL-RU
Copy link
Owner

SL-RU commented Jun 19, 2022

But can that value be something else then 0B, for example 5B?

@SL-RU SL-RU added the bug Something isn't working label Jun 19, 2022
@jra419
Copy link
Contributor

jra419 commented Jun 24, 2022

But can that value be something else then 0B, for example 5B?

Yes, my mistake. I did not have any other occurrences besides 0B, but from checking, the value could be different. A generic replacement would be more correct. @SL-RU, do you want to revert the PR / should I open a new one?

I've noticed that this issue is apparently due to a lsblk bug that will be fixed in the next release, util-linux/util-linux#1636. This should also remove the need for the one-liner fix in the near future.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants