Traceback (most recent call last):
File "/usr/local/bin/mikrocataTZSP0.py", line 403, in <module>
main()
File "/usr/local/bin/mikrocataTZSP0.py", line 386, in main
notifier.loop()
File "/usr/local/lib/python3.9/dist-packages/pyinotify.py", line 1376, in loop
self.process_events()
File "/usr/local/lib/python3.9/dist-packages/pyinotify.py", line 1275, in process_events
self._default_proc_fun(revent)
File "/usr/local/lib/python3.9/dist-packages/pyinotify.py", line 910, in __call__
return _ProcessEvent.__call__(self, event)
File "/usr/local/lib/python3.9/dist-packages/pyinotify.py", line 630, in __call__
return meth(event)
File "/usr/local/bin/mikrocataTZSP0.py", line 77, in process_IN_MODIFY
add_to_tik(read_json(FILEPATH))
File "/usr/local/bin/mikrocataTZSP0.py", line 114, in read_json
alerts = [ujson.loads(line) for line in f.readlines()]
File "/usr/local/bin/mikrocataTZSP0.py", line 114, in <listcomp>
alerts = [ujson.loads(line) for line in f.readlines()]
ujson.JSONDecodeError: Unmatched '"' when decoding 'string'
I rewrote the read_json function and now the script works stably without errors:
def read_json(fpath):
global last_pos
try:
with open(fpath, "r") as f:
f.seek(last_pos)
alerts = []
for line in f.readlines():
try:
alerts.append(ujson.loads(line))
except ujson.JSONDecodeError as e:
print(f"JSON decoding error: {e}\nLine: {line}")
last_pos = f.tell()
return alerts
except FileNotFoundError:
print(f"[Mikrocata] File: {fpath} not found. Retrying in 10 seconds..")
sleep(10)
systemd crashed every minute, I found this error:
I rewrote the read_json function and now the script works stably without errors: