0

I wanted to use pyshark to capture network traffic, so naturally I searched first for the most simple examples. Having found a recipe to make a daily cron job, i changed it to capture for a minute.

import pyshark

file = 'c:\\qu\\test.pcap'
output = open(file, "w")
time = 60
capture = pyshark.LiveCapture(interface="WiFi", output_file=file)
capture.sniff(timeout=time)
output.close()

of course, it didn't work! but this error message totally threw me. What does it mean?

c:\Users\userad>py shark1.py
Traceback (most recent call last):
  File "c:\Users\usera\shark1.py", line 5, in <module>
    capture = pyshark.LiveCapture(interface="WiFi", output_file=file)
  File "C:\Python39\lib\site-packages\pyshark\capture\live_capture.py", line 58, in __init__
    all_interfaces = get_tshark_interfaces(tshark_path)
  File "C:\Python39\lib\site-packages\pyshark\tshark\tshark.py", line 114, in get_tshark_interfaces
    tshark_interfaces = subprocess.check_output(parameters, stderr=null).decode("utf-8")
  File "C:\Python39\lib\subprocess.py", line 420, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "C:\Python39\lib\subprocess.py", line 524, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['C:/Program Files/Wireshark/tshark.exe', '-D']' returned non-zero exit status 2.
SlightlyKosumi
  • 701
  • 2
  • 8
  • 24
  • PyShark is initiating a subprocess with the command `C:/Program Files/Wireshark/tshark.exe -D`, which is failing. Please, try running the same command manually from CMD and share the output, so as to get a better understanding of the command's error. – Zero Jun 21 '23 at 22:18
  • Did you ever figure out the issue? – Life is complex Jun 26 '23 at 13:12
  • 1
    I tried on a different machine, and there the code worked fine. So I believe it is down to the manner in which I tried to install tshark. I tried a tshark dev install ... seems just installing via Wireshark download is better – SlightlyKosumi Jun 27 '23 at 14:49

0 Answers0