From 9ee3278a62f04c8fd7263fbf94edced10a904ff9 Mon Sep 17 00:00:00 2001 From: scifijunkie Date: Mon, 22 Apr 2024 18:02:11 +0000 Subject: [PATCH] Addressing errors Addressed the "Internal Server Error The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application." error. Addressed the "[ERROR] Error: send_from_directory() missing 1 required positional argument: 'path'" error. --- handshakes-dl.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/handshakes-dl.py b/handshakes-dl.py index 09324d4..9fe8b3f 100644 --- a/handshakes-dl.py +++ b/handshakes-dl.py @@ -87,15 +87,20 @@ class HandshakesDL(plugins.Plugin): if path == "/" or not path: handshakes = glob.glob(os.path.join("/home/pi", "*.pcap")) - handshakes = [os.path.basename(path)[:-5] for path in handshakes] + handshakes = [os.path.basename(handshake) for handshake in handshakes] return render_template_string(TEMPLATE, title="Handshakes | " + pwnagotchi.name(), handshakes=handshakes) else: - dir = "/home/pi" + directory = "/home/pi" try: - logging.info(f"[HandshakesDL] serving {dir}/{path}.pcap") - return send_from_directory(directory=dir, filename=path+'.pcap', as_attachment=True) + file_path = os.path.join(directory, path) + logging.info(f"[HandshakesDL] serving {file_path}") + return send_from_directory(directory=directory, path='.', filename=path, as_attachment=True) except FileNotFoundError: + logging.error("File not found") abort(404) + except Exception as e: + logging.error(f"Error: {e}") + abort(500)