-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Ya sé que se pide tener la estructura de carpetas pero cuando es la primera vez que ejecutas el script si no existe la carpeta docs arroja un error y se puede evitar:
PS C:\Support\Scripts\python\Packet capture\scripts> python .\analyze_traffic.py sloldap12.pcap
Analyzing file: data\sloldap12.pcap
Traceback (most recent call last):
File "C:\Support\Scripts\python\Packet capture\scripts\analyze_traffic.py", line 70, in <module>
main(pcap_file)
~~~~^^^^^^^^^^^
File "C:\Support\Scripts\python\Packet capture\scripts\analyze_traffic.py", line 51, in main
pdf.save()
~~~~~~~~^^
File "C:\Program Files\Python313\Lib\site-packages\reportlab\pdfgen\canvas.py", line 1299, in save
self._doc.SaveToFile(self._filename, self)
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python313\Lib\site-packages\reportlab\pdfbase\pdfdoc.py", line 208, in SaveToFile
f = open(filename, "wb")
FileNotFoundError: [Errno 2] No such file or directory: 'docs\\network_analysis_report.pdf'
entiendo que debería hacerse una comprobación y generar la carpeta, añadiendo, por ejemplo:
import pathlib <------- esta importación
[...]
def main(pcap_file):
print(f"Analyzing file: {pcap_file}")
cap = pyshark.FileCapture(pcap_file)
packet_count = 0
pdf_path = os.path.join('docs', 'network_analysis_report.pdf')
pathlib.Path(pdf_path).mkdir(parents=True, exist_ok=True) <------- esta línea
pdf = canvas.Canvas(pdf_path, pagesize=letter)
pdf.setFont("Helvetica", 12)
y_position = 750 # Start at the top of the page
[...]
gracias.
Metadata
Metadata
Assignees
Labels
No labels