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

pretty_print TypeError when using ek+raw mode #586

Open
miaotony opened this issue Aug 19, 2022 · 1 comment
Open

pretty_print TypeError when using ek+raw mode #586

miaotony opened this issue Aug 19, 2022 · 1 comment
Labels

Comments

@miaotony
Copy link
Contributor

miaotony commented Aug 19, 2022

Describe the bug
config: use_ek=True, include_raw=True
Pyshark raises TypeError: 'NoneType' object is not iterable when calling packet.pretty_print() or packet.__str__() function.

To Reproduce

import pyshark

def tshark_callback(packet):
    packet.pretty_print()
    # print(packet.__str__())

cap = pyshark.LiveCapture(use_ek=True, include_raw=True, interface='wlan')
cap.set_debug()
cap.apply_on_packets(tshark_callback)

Run the code and surf on the Internet for some time, the program exit with the following error.

图片

...
Layer TLS:
Layer FRAME_RAW:
Layer ETH_RAW:
Layer IP_RAW:
Layer TCP_RAW:
Layer TCP_TCP_SEGMENTS_RAW:
Layer TCP_TCP_SEGMENTS:
2022-08-20 03:28:44,374 - LiveCapture - DEBUG - Cleanup Subprocess (pid 18028)
2022-08-20 03:28:44,395 - LiveCapture - DEBUG - Cleanup Subprocess (pid 26176)
Traceback (most recent call last):
  File "test.py", line 9, in <module>
    cap.apply_on_packets(tshark_callback)
  File "D:\Programs\Anaconda\lib\site-packages\pyshark\capture\capture.py", line 256, in apply_on_packets
    return self.eventloop.run_until_complete(coro)
  File "D:\Programs\Anaconda\lib\asyncio\base_events.py", line 584, in run_until_complete
    return future.result()
  File "D:\Programs\Anaconda\lib\site-packages\pyshark\capture\capture.py", line 267, in packets_from_tshark
    await self._go_through_packets_from_fd(tshark_process.stdout, packet_callback, packet_count=packet_count)
  File "D:\Programs\Anaconda\lib\site-packages\pyshark\capture\capture.py", line 294, in _go_through_packets_from_fd
    packet_callback(packet)
  File "test.py", line 4, in tshark_callback
    packet.pretty_print()
  File "D:\Programs\Anaconda\lib\site-packages\pyshark\packet\packet.py", line 114, in pretty_print
    layer.pretty_print()
  File "D:\Programs\Anaconda\lib\site-packages\pyshark\packet\layers\base.py", line 59, in pretty_print
    self._pretty_print_layer_fields(writer)
  File "D:\Programs\Anaconda\lib\site-packages\pyshark\packet\layers\ek_layer.py", line 110, in _pretty_print_layer_fields
    for field_name in self.field_names:
  File "D:\Programs\Anaconda\lib\site-packages\pyshark\packet\layers\ek_layer.py", line 65, in field_names
    return list({field_name.split("_", 1)[0] for field_name in self.all_field_names})
  File "D:\Programs\Anaconda\lib\site-packages\pyshark\packet\layers\ek_layer.py", line 71, in all_field_names
    for field_name in self._fields_dict:
TypeError: 'NoneType' object is not iterable

Versions (please complete the following information):

  • OS: Windows 10
  • pyshark version: v0.5.3
  • tshark version: TShark (Wireshark) 3.6.6 (v3.6.6-0-g7d96674e2a30)
@miaotony miaotony added the bug label Aug 19, 2022
@miaotony
Copy link
Contributor Author

The bug also occurs on Linux (Ubuntu 20.04) with pyshark v0.5.3 and TShark (Wireshark) 3.2.3 (Git v3.2.3 packaged as 3.2.3-1).

图片

Layer FRAME_RAW:
Layer ETH_RAW:
Layer IP_RAW:
Layer TCP_RAW:
Layer TCP_TCP_SEGMENTS_RAW:
Layer TCP_TCP_SEGMENTS:
2022-08-19 19:20:43,419 - LiveCapture - DEBUG - Cleanup Subprocess (pid 11566)
2022-08-19 19:20:43,424 - LiveCapture - DEBUG - Cleanup Subprocess (pid 11538)
Traceback (most recent call last):
  File "/workspaces/test.py", line 9, in <module>
    cap.apply_on_packets(tshark_callback)  
  File "/opt/python/3.10.4/lib/python3.10/site-packages/pyshark/capture/capture.py", line 256, in apply_on_packets
    return self.eventloop.run_until_complete(coro)
  File "/opt/python/3.10.4/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete
    return future.result()
  File "/opt/python/3.10.4/lib/python3.10/site-packages/pyshark/capture/capture.py", line 267, in packets_from_tshark
    await self._go_through_packets_from_fd(tshark_process.stdout, packet_callback, packet_count=packet_count)
  File "/opt/python/3.10.4/lib/python3.10/site-packages/pyshark/capture/capture.py", line 294, in _go_through_packets_from_fd
    packet_callback(packet)
  File "/workspaces/test.py", line 4, in tshark_callback
    packet.pretty_print()
  File "/opt/python/3.10.4/lib/python3.10/site-packages/pyshark/packet/packet.py", line 114, in pretty_print
    layer.pretty_print()
  File "/opt/python/3.10.4/lib/python3.10/site-packages/pyshark/packet/layers/base.py", line 59, in pretty_print
    self._pretty_print_layer_fields(writer)
  File "/opt/python/3.10.4/lib/python3.10/site-packages/pyshark/packet/layers/ek_layer.py", line 110, in _pretty_print_layer_fields
    for field_name in self.field_names:
  File "/opt/python/3.10.4/lib/python3.10/site-packages/pyshark/packet/layers/ek_layer.py", line 65, in field_names
    return list({field_name.split("_", 1)[0] for field_name in self.all_field_names})
  File "/opt/python/3.10.4/lib/python3.10/site-packages/pyshark/packet/layers/ek_layer.py", line 71, in all_field_names
    for field_name in self._fields_dict:
TypeError: 'NoneType' object is not iterable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant