在使用dpkt解析UDP pcap时,得到了以下错误消息:
with open('file.pcap', 'rb') as fopen:
pcap = dpkt.pcap.Reader(fopen)
for timestamp, buf in pcap:
print (timestamp)错误:root:检查模块中的内部Python错误。下面是这个内部错误的回溯。
回溯(最近一次调用):ValueError:读取关闭文件
在处理上述异常的过程中,发生了另一个异常:
回溯(最近一次调用):AttributeError:'ValueError‘对象没有属性'render_traceback’
在处理上述异常的过程中,发生了另一个异常:
回溯(最近一次调用):AssertionError
发布于 2020-08-05 18:31:54
离开with open(...) ...块时,文件将自动关闭:
with open('file.pcap', 'rb') as fopen:
# still open here
pcap = dpkt.pcap.Reader(fopen)
# automatically closed here
for timestamp, buf in pcap:
print (timestamp)因此,您需要将pcap读取放在打开文件的同一个块中:
with open('file.pcap', 'rb') as fopen:
pcap = dpkt.pcap.Reader(fopen)
for timestamp, buf in pcap:
print (timestamp)https://stackoverflow.com/questions/63270602
复制相似问题