How to fix ValueError: read of closed file while parsing a pcap using dpkt
How to fix ValueError: read of closed file while parsing a pcap using dpkt
我是网络新手,我正在尝试使用 dpkt
解析 pcap
,但我得到
ValueError: read of closed file.
代码如下:
import dpkt
f = open('test.pcapng', 'rb')
pcap = dpkt.pcap.Reader(f)
for timestamp, buf in pcap:
print (timestamp)
这是结果:
1542964953.074129 Traceback (most recent call last): File "C:\Users\User\Documents\testdpkt1.py", line 19, in
for ts, buf in pcap: File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\site-packages\dpkt\pcap.py",
line 312, in iter
buf = self.f.read(PktHdr.__hdr_len) ValueError: read of closed file
你试过了吗?
with open('test.pcapng', 'rb') as f:
pcap = dpkt.pcap.Reader(f)
for timestamp, buf in pcap:
print (timestamp)
这应该可以防止文件被关闭
我是网络新手,我正在尝试使用 dpkt
解析 pcap
,但我得到
ValueError: read of closed file.
代码如下:
import dpkt
f = open('test.pcapng', 'rb')
pcap = dpkt.pcap.Reader(f)
for timestamp, buf in pcap:
print (timestamp)
这是结果:
1542964953.074129 Traceback (most recent call last): File "C:\Users\User\Documents\testdpkt1.py", line 19, in for ts, buf in pcap: File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\site-packages\dpkt\pcap.py", line 312, in iter buf = self.f.read(PktHdr.__hdr_len) ValueError: read of closed file
你试过了吗?
with open('test.pcapng', 'rb') as f:
pcap = dpkt.pcap.Reader(f)
for timestamp, buf in pcap:
print (timestamp)
这应该可以防止文件被关闭