最近,我在Pycharm上安装了Pyshark。这是我的代码:

import pyshark
cap = pyshark.FileCapture('/root/captures/initialize_db.pcap')
print (dir(cap[184]['DB-LSP-DISC']))


跑步时,我会得到答案以及一些警告:

['DATA_LAYER', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattr__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_all_fields', '_field_prefix', '_get_all_field_lines', '_get_all_fields_with_alternates', '_get_field_or_layer_repr', '_get_field_repr', '_layer_name', '_sanitize_field_name', 'field_names', 'get', 'get_field', 'get_field_by_showname', 'get_field_value', 'json_array', 'json_key', 'json_member', 'json_object', 'json_value_number', 'json_value_string', 'layer_name', 'pretty_print', 'raw_mode']
Exception ignored in: <bound method BaseEventLoop.__del__ of <_UnixSelectorEventLoop running=False closed=True debug=False>>
Traceback (most recent call last):
  File "/usr/lib/python3.5/asyncio/base_events.py", line 510, in __del__
  File "/usr/lib/python3.5/asyncio/unix_events.py", line 65, in close
  File "/usr/lib/python3.5/asyncio/unix_events.py", line 146, in remove_signal_handler
  File "/usr/lib/python3.5/signal.py", line 47, in signal
TypeError: signal handler must be signal.SIG_IGN, signal.SIG_DFL, or a callable object
Exception ignored in: <generator object Capture._packets_from_tshark_sync at 0x7f4787d2eba0>
Traceback (most recent call last):
  File "/root/PycharmProjects/Dropbox/venv/lib/python3.5/site-packages/pyshark/capture/capture.py", line 229, in _packets_from_tshark_sync
  File "/usr/lib/python3.5/asyncio/base_events.py", line 443, in run_until_complete
  File "/usr/lib/python3.5/asyncio/base_events.py", line 357, in _check_closed
RuntimeError: Event loop is closed
sys:1: RuntimeWarning: coroutine 'Capture._cleanup_subprocess' was never awaited
Exception ignored in: <bound method BaseSubprocessTransport.__del__ of <_UnixSubprocessTransport closed pid=20639 running stdout=<_UnixReadPipeTransport closing fd=7 open>>>
Traceback (most recent call last):
  File "/usr/lib/python3.5/asyncio/base_subprocess.py", line 131, in __del__
  File "/usr/lib/python3.5/asyncio/base_subprocess.py", line 106, in close
  File "/usr/lib/python3.5/asyncio/unix_events.py", line 414, in close
  File "/usr/lib/python3.5/asyncio/unix_events.py", line 442, in _close
  File "/usr/lib/python3.5/asyncio/base_events.py", line 572, in call_soon
  File "/usr/lib/python3.5/asyncio/base_events.py", line 357, in _check_closed
RuntimeError: Event loop is closed


我在虚拟环境中运行Python 3.5.3。

最佳答案

对我来说,当我在代码末尾放置exit()函数时,错误消失了。我不知道为什么? (实际上,这让我想起了这个模因:)

https://pics.me.me/my-code-doesnt-work-ihave-noidea-why-my-code-works-28614548.png

关于python - 乳清在python3虚拟环境上运行pyshark时出现错误?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52349337/

10-10 12:38