JarryShaw / PyPCAPKit

Python-based Comprehensive Network Packet Analysis Library

Home Page:https://jarryshaw.github.io/PyPCAPKit/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pcapkit.extraction not working

bunderuso opened this issue · comments

Describe the bug
A clear and concise description of what the bug is.
Attempting to follow the test file "test_extraction.py" and receiving the error ValueError: too many values to unpack (expected 2)

System information
A clear and concise description of your system information.

  • OS Version: Windows 10 19045.3324
  • Python Version: 3.10
  • Python Implementation: pycharm

Traceback stack

Traceback (most recent call last):
File "C:\Users----\PycharmProjects\----\----\test.py", line 8, in
pcapkit.extract('in.pcap', 'out.json', 'json')
ValueError: too many values to unpack (expected 2)

Note the ---- are to remove PI from file path

Expected behavior
Upon running this test program I expect the provided sample pcap file to be extracted to JSON as it is shown in the "sample" directory in GitHub

Additional context
Add any other context about the problem here.

Note that is error is present when there are no parameters provided to the function, the function is assigned to no variable, two variables are assigned to the function and using a different pcap file

Please kindly set PCAPKIT_DEVMODE=1 in the environment variables and provide the re-generated traceback information with more details. Also, the contents of test.py and its sibling files would be much appreciated.

test,py file contents

import pcapkit
import os
os.environ["PCAPKIT_DEVMODE"] = 1

#pcapkit.extract()
pcapkit.extract('in.pcap', 'out.json', 'json')

#pcapkit.extract(fin="Enabled.pcap", format='json')

Traceback (most recent call last):
File "C:\Users\----\PycharmProjects\----\----\----test.py", line 5, in
os.environ["PCAPKIT_DEVMODE"] = 1
File "C:\Users\----\AppData\Local\Programs\Python\Python310\lib\os.py", line 684, in setitem
value = self.encodevalue(value)
File "C:\Users\----\AppData\Local\Programs\Python\Python310\lib\os.py", line 742, in check_str
raise TypeError("str expected, not %s" % type(value).name)
TypeError: str expected, not int

(venv) PS C:\Users\\----\PycharmProjects\i-regress\pyshark_poc> python .\raja_test.py
C:\Users\\----\PycharmProjects\i-regress\venv\lib\site-packages\pcapkit\__init__.py:0: DevModeWarning: development mode enabled
  PCAPKIT_DEVMODE=1                                                                                                                
Traceback (most recent call last):
  File "C:\Users\\----\PycharmProjects\\----\\----\test.py", line 8, in <module>                                          
pcapkit.extract('in.pcap', 'out.json', 'json')                                                                                           
File "C:\Users\\----\PycharmProjects\i-regress\venv\lib\site-packages\pcapkit\interface\core.py", line 122, in extract                 
    return Extractor(fin=fin, fout=fout, format=format,                                                                                      
  File "C:\Users\\----\PycharmProjects\i-regress\venv\lib\site-packages\pcapkit\foundation\extraction.py", line 771, in __init__         
    self.run()    # start extraction                                                                                                         
  File "C:\Users\\----\PycharmProjects\i-regress\venv\lib\site-packages\pcapkit\foundation\extraction.py", line 417, in run              
    self.record_frames()                                                                                                                     
  File "C:\Users\\----\PycharmProjects\i-regress\venv\lib\site-packages\pcapkit\foundation\extraction.py", line 568, in 
record_frames    
    self._exeng.read_frame()                                                                                                                 
  File "C:\Users\\----\PycharmProjects\i-regress\venv\lib\site-packages\pcapkit\foundation\engines\pcap.py", line 139, in 
read_frame     
    frame = Frame(ext._ifile, num=ext._frnum+1, header=self._gbhdr.info,                                                                     
  File "C:\Users\\----\PycharmProjects\i-regress\venv\lib\site-packages\pcapkit\protocols\protocol.py", line 497, in __init__            
    self.__post_init__(file, length, **kwargs)  # type: ignore[arg-type]                                                                     
  File "C:\Users\\----\PycharmProjects\i-regress\venv\lib\site-packages\pcapkit\protocols\misc\pcap\frame.py", line 350, in 
__post_init__
    self._info = self.unpack(length, _read=_read, **kwargs)                                                                                  
  File "C:\Users\\----\PycharmProjects\i-regress\venv\lib\site-packages\pcapkit\protocols\misc\pcap\frame.py", line 192, in 
unpack       
    return self.read(length, **kwargs)
  File "C:\Users\\----\PycharmProjects\i-regress\venv\lib\site-packages\pcapkit\protocols\misc\pcap\frame.py", line 260, in 
read
    return self._decode_next_layer(frame, self._ghdr.network, frame.len)
  File "C:\Users\\----\PycharmProjects\i-regress\venv\lib\site-packages\pcapkit\protocols\misc\pcap\frame.py", line 463, in 
_decode_next_layer
    dict_.__update__({
  File "C:\Users\\----\PycharmProjects\i-regress\venv\lib\site-packages\pcapkit\corekit\infoclass.py", line 275, in __update__
    for (key, value) in data_iter:
ValueError: too many values to unpack (expected 2)

same here, this thing is broken!

I added some trace to see what the non-tuple elements are, they're strings like this:

foo='pre'
foo='del'
foo='thr'
foo='rel'
foo='ecn'
foo='raw'
foo='__next_type__'
foo='__next_name__'
foo='udp'
foo='__next_type__'
foo='__next_name__'
foo='ipv4'
foo='__next_type__'
foo='__next_name__'
foo='ethernet'
foo='protocols'
foo='__next_type__'
foo='__next_name__'
foo='pre'
foo='del'
foo='thr'
foo='rel'
foo='ecn'
...

(which are "too many values to unpack" because they are strings with more than two characters)

works at 1.1.0.post3, broken at 1.1.1

Okay, it seems that this is a Python 3.10 specific problem. I'll look into it.

Fixed in version 1.2.2

Fixed in version 1.2.2