I'm using pyshark
and are trying to print out JSON
. This is my code:
import pyshark
import json
capture = pyshark.LiveCapture(interface='eth0', bpf_filter='http', use_json=True)
for packet in capture.sniff_continuously(packet_count=10):
print(json.loads(str(packet)))
But I'm getting the error:
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Also, when simply running print(packet)
it isn't JSON
.
UPDATE
I've tried with this:
cmd = 'tshark -i en0 -f http -T json -x -l --no-duplicate-keys'
args = shlex.split(cmd)
tshark = subprocess.Popen(args, stdout=subprocess.PIPE)
for line in io.TextIOWrapper(tshark.stdout, encoding="utf-8"):
print("test: %s" % line.rstrip())
But that print out every single line of the JSON
object instead of one combined object, guess it's because of the pipe.
Can this be changed so I have the actual JSON
object per packet?