JSON Decode Error
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?
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
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)
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 -Oand get a good json format. I was wondering if this can be from json.load() function?
same error here but (char 1686)
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.
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.
@Shinkirou Good find! I think this is the fix. Do you want to PR it?
But can that value be something else then 0B, for example 5B?
But can that value be something else then
0B, for example5B?
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, https://github.com/util-linux/util-linux/issues/1636. This should also remove the need for the one-liner fix in the near future.