2
import dpkt

f = open('gtp.pcap')

pcap = dpkt.pcap.Reader(f)

for ts, buf in pcap:
       eth = dpkt.ethernet.Ethernet(buf)

print(eth)

Traceback (most recent call last):
  File "new.py", line 4, in <module>
    pcap = dpkt.pcap.Reader(f)
  File "/home/user/gtp_gaurang/venv/lib/python3.5/site-packages/dpkt/pcap.py", line 244, in __init__
    buf = self.__f.read(FileHdr.__hdr_len__)
  File "/usr/lib/python3.5/codecs.py", line 321, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 16: invalid start byte
(venv) user@user-OptiPlex-7010:~/gtp_gaurang$ python3 new.py
Traceback (most recent call last):
  File "new.py", line 4, in <module>
    pcap = dpkt.pcap.Reader(f)
  File "/home/user/gtp_gaurang/venv/lib/python3.5/site-packages/dpkt/pcap.py", line 244, in __init__
    buf = self.__f.read(FileHdr.__hdr_len__)
  File "/usr/lib/python3.5/codecs.py", line 321, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 16: invalid start byte

What is this error when i try to parse a simple pcap file?

I am running this simple pcap parser code. But it is showing the above error. Can anyone please help.

Gaurang Patel
  • 172
  • 3
  • 11

2 Answers2

1

Can you please check this link. Related Answer

according to the answer suggestion, UTF-8 encounters an invalid byte which it cannot decode. So if you just read your file in binary format this error will not come as the decoding will not happen and the file contents will remain a bytes.

Darth_Sourav
  • 116
  • 7
0

Open the file in binary mode

f = open('gtp.pcap', 'rb')
pcap = dpkt.pcap.Reader(f)
...
Jossef Harush Kadouri
  • 32,361
  • 10
  • 130
  • 129