Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pcapreader() does not work with PosixPath from Python's pathlib #3596

Closed
tanwirahmad opened this issue May 4, 2022 · 0 comments
Closed

Pcapreader() does not work with PosixPath from Python's pathlib #3596

tanwirahmad opened this issue May 4, 2022 · 0 comments

Comments

@tanwirahmad
Copy link

Brief description

Pcapreader() is expecting the fname parameter to be in str. However, after the release of pathlib in Python 3.4, file paths can exist as PosixPath or WindowsPath instances on Unix or Windows OS, respectively.

Scapy version

2.4.5

Python version

3.8

Operating system

Ubuntu 20.04

Additional environment information

No response

How to reproduce

from pathlib import Path
from scapy.all import *

pcap_file = Path('/home/my/network_traffic.pcap')
cap = PcapReader(pcap_file)

Actual result

Traceback (most recent call last):
  File "preprocess_scapy.py", line 4
    cap = PcapReader(pcap_file)
  File "/home/my/.venv/pcap/lib/python3.8/site-packages/scapy/utils.py", line 1151, in __call__
    filename, fdesc, magic = cls.open(filename)
  File "/home/my/.venv/pcap/lib/python3.8/site-packages/scapy/utils.py", line 1189, in open
    magic = fdesc.read(4)
AttributeError: 'PosixPath' object has no attribute 'read'

Expected result

No response

Related resources

No response

gpotter2 pushed a commit to tanwirahmad/scapy that referenced this issue Jul 26, 2022
@guedou guedou closed this as not planned Won't fix, can't repro, duplicate, stale Dec 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants