0

I'm trying to use pyshark and nest_asyncio in an attempt to read a sample PCAP file and export the contents into an XML file written in the following:

import pyshark
import nest_asyncio
nest_asyncio.apply()

pcap_path = '\Downloads\sampleHTTP_capture.pcap'
# replace input.pcap with the path to your input PCAP file
cap = pyshark.FileCapture("sampleHTTP_capture.pcap")
# assume the path to TShark is the default if not change to your location of TShark
pyshark.tshark.tshark_path = '/usr/bin/tshark'
# replace output.xml with the name of the output xml file you wish to create
with open("test.xml", "w") as f:
    f.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
    f.write("<pcap>\n")

    for pkt in cap:
        f.write("\t<packet>\n")

        for field in pkt:
            if hasattr(field, 'field_name') and hasattr(field, 'raw_value'):
                f.write("\t\t<{0}>{1}</{0}>\n".format(field.field_name, field.raw_value))

        f.write("\t</packet>\n")

    f.write("</pcap>\n")

I was able to implement the code in google collab by making some modifications however when running the code above in PyCharm I run into this issue:

AttributeError: type object 'Task' has no attribute 'all_tasks'

I understand from the traceback the error is occurring in this line here

cap = pyshark.FileCapture("sampleHTTP_capture.pcap")

However I'm not sure why this became an issue only when I tried to implement and run this code on my IDE, when the code is almost the same as when implemented in google collab.

Any ideas to why this might be happening? Or how to fix it? Thanks for your time

Floresss
  • 1
  • 1

0 Answers0