pyshark
pyshark copied to clipboard
The File Capture Fails When the Working Directory Has a File Called 'config.ini'
Describe the bug
The file capture object fails to read a .pcapng
file when the working directory has a specific file called config.ini.
I was keeping some other configuration in a file of that name, as part of a packet processing pipeline. But seems somehow pyshark
tries to access that file and looks for a section called tshark
.
To Reproduce Code sample
#!/usr/bin/env python3
# encoding: utf-8
import pyshark as ps
filename:str = 'some_file.pcapng' # Any pcap file should serve the purpose to reproduce the error
with ps.FileCapture(input_file=filename) as capture:
print(capture[0].pretty_print()) # Fails when 'config.ini' present in the directory
Expected behavior I expect the above code to print the information about the first packet in the file.
Versions
- Ubuntu 20.04
- pyshark 0.5.3
- TShark (Wireshark) 3.2.3 (Git v3.2.3 packaged as 3.2.3-1)
- Python 3.8.10
Stack Trace
File "/home/barmanroys/.local/lib/python3.8/site-packages/pyshark/capture/capture.py", line 212, in _packets_from_tshark_sync
tshark_process = existing_process or self.eventloop.run_until_complete(
File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
return future.result()
File "/home/barmanroys/.local/lib/python3.8/site-packages/pyshark/capture/capture.py", line 340, in _get_tshark_process
parameters = [self._get_tshark_path(), "-l", "-n", "-T", output_type] + \
File "/home/barmanroys/.local/lib/python3.8/site-packages/pyshark/capture/capture.py", line 315, in _get_tshark_path
return get_process_path(self.tshark_path)
File "/home/barmanroys/.local/lib/python3.8/site-packages/pyshark/tshark/tshark.py", line 38, in get_process_path
possible_paths.append(config.get(process_name, "%s_path" % process_name))
File "/usr/lib/python3.8/configparser.py", line 781, in get
d = self._unify_values(section, vars)
File "/usr/lib/python3.8/configparser.py", line 1149, in _unify_values
raise NoSectionError(section) from None