FileNotFoundError Bug: Kleinanzeigen-Bot Issue & Fixes

by Sebastian Müller 55 views

Hey guys! 👋 We've got a bug report here from a user experiencing a FileNotFoundError while trying to download items using the kleinanzeigen-bot. Let's dive into the details and see what's going on.

Discussion Category

This issue falls under the Second-Hand-Friends and kleinanzeigen-bot categories, which means it's related to downloading items from classifieds websites.

Additional Information

🔄 Tested on Latest Release

The user has confirmed that they can reproduce this issue on the latest version of the bot. This is super helpful because it means we're dealing with a current problem, not something that's already been fixed. 👍

✔️ Expected Behaviour

The user expects the bot to download their items without any errors. Makes sense, right? 😉

🐞 Actual Behaviour

Instead, the download process starts, but an error pops up every time at the first item. Here's the error message they're seeing:

Starte den Download noch nicht heruntergeladener Anzeigen...
[INFO] Extrahiere Informationen aus Anzeige mit Titel [Riani Hemdblusenkleid grün, Größe 38]
[INFO] 4 imagen gefunden.
[FEHLER] FileNotFoundError: [Errno 2] No such file or directory: 'downloaded-ads/ad_3145748007/ad_3145748007__img1.jpg'

This FileNotFoundError indicates that the bot is trying to access a file that doesn't exist at the specified path. It seems like there's an issue with how the bot is handling file paths or how the files are being saved. 🤔

📋 Steps to Reproduce

To reproduce the issue, the user is running the following commands:

open -a "Google Chrome" --args --remote-debugging-port=9222 --user-data-dir=/tmp/chrome-debug-profile  --disable-dev-shm-usage && ./kleinanzeigen-bot download

This command launches Chrome with remote debugging enabled and then runs the kleinanzeigen-bot download command. This is great because it gives us a clear set of steps to follow to try and replicate the bug ourselves. 🤓

💻 What Operating Systems Are You Seeing the Problem On?

The user is experiencing this issue on MacOS. This is important information because it helps us narrow down the potential causes. Maybe it's a platform-specific issue? 🤷‍♀️

📺 What Browsers Are You Seeing the Problem On? (if applicable)

The problem is occurring in Chrome. Knowing the browser helps us rule out any browser-specific quirks or compatibility issues. ✅

📃 Relevant Log Output (if applicable)

The user has provided a detailed log output, which is super helpful! Let's break it down:

2025-08-16 19:41:29,597 [INFO] App Version: 2025+91a40b0
2025-08-16 19:41:29,600 [INFO] Python Version: 3.13.5 (v3.13.5:6cb20a219a8, Jun 11 2025, 12:23:45) [Clang 16.0.0 (clang-1600.0.26.6)]
2025-08-16 19:41:29,603 [WARNING] Es wurden keine Anzeigen-Selektor angegeben. Es wird "new" verwendet.
2025-08-16 19:41:29,607 [INFO] Lade Konfiguration von [/Users/asteeg/Documents/kleinanzeigen_betti/config.yaml]...
2025-08-16 19:41:29,710 [INFO] -> 665 Kategorien gefunden
2025-08-16 19:41:29,712 [INFO] Lade [/Users/asteeg/Documents/kleinanzeigen_betti/.temp/update_check_state.json]...
2025-08-16 19:41:29,716 [INFO] Erstelle Browser-Sitzung...
2025-08-16 19:41:29,719 [INFO]  -> Browser-Programmpfad: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
2025-08-16 19:41:29,721 [INFO] Verwende existierenden Browser-Prozess unter 127.0.0.1:9222
2025-08-16 19:41:30,055 [INFO] Neue Browser-Sitzung ist ws://127.0.0.1:9222/devtools/browser/69d2fcf6-3923-4494-a140-b8c5bd452491
2025-08-16 19:41:30,058 [INFO] Überprüfe, ob bereits eingeloggt...
2025-08-16 19:41:32,389 [INFO] Bereits eingeloggt als [[email protected]]. Überspringe Anmeldung.
2025-08-16 19:41:32,392 [INFO] Scanne Anzeigenübersicht...
2025-08-16 19:41:33,543 [INFO]  ... pausing for 2461 ms ...
2025-08-16 19:41:37,104 [INFO] Mehrere Anzeigenseiten erkannt.
2025-08-16 19:41:37,108 [INFO] Extrahiere Anzeigen von Seite 1...
2025-08-16 19:41:39,450 [INFO]  ... pausing for 2642 ms ...
2025-08-16 19:41:44,782 [INFO] 25 Anzeigen-Elemente auf Seite 1 gefunden.
2025-08-16 19:41:47,589 [INFO] 25 Referenzen von Seite 1 erfolgreich extrahiert.
2025-08-16 19:41:48,053 [INFO] Navigiere zur nächsten Seite...
2025-08-16 19:41:48,195 [INFO]  ... pausing for 3931 ms ...
2025-08-16 19:41:52,139 [INFO] Extrahiere Anzeigen von Seite 2...
2025-08-16 19:41:55,044 [INFO]  ... pausing for 2538 ms ...
2025-08-16 19:42:00,236 [INFO] 25 Anzeigen-Elemente auf Seite 2 gefunden.
2025-08-16 19:42:03,049 [INFO] 25 Referenzen von Seite 2 erfolgreich extrahiert.
2025-08-16 19:42:03,537 [INFO] Navigiere zur nächsten Seite...
2025-08-16 19:42:03,673 [INFO]  ... pausing for 3776 ms ...
2025-08-16 19:42:07,458 [INFO] Extrahiere Anzeigen von Seite 3...
2025-08-16 19:42:08,228 [INFO]  ... pausing for 2520 ms ...
2025-08-16 19:42:11,141 [INFO] 3 Anzeigen-Elemente auf Seite 3 gefunden.
2025-08-16 19:42:11,478 [INFO] 3 Referenzen von Seite 3 erfolgreich extrahiert.
2025-08-16 19:42:17,270 [INFO] Keine Paginierungssteuerung nach dem Scrollen/Warten gefunden. Es wird von der letzten Seite ausgegangen.
2025-08-16 19:42:17,312 [INFO] 53 Anzeigen gefunden.
2025-08-16 19:42:17,316 [INFO] Suche nach Anzeigendateien...
2025-08-16 19:42:17,323 [INFO] -> 0 Anzeigendateien gefunden
2025-08-16 19:42:17,326 [INFO] Starte den Download noch nicht heruntergeladener Anzeigen...
2025-08-16 19:42:24,980 [INFO] Extrahiere Informationen aus Anzeige mit Titel "Riani Hemdblusenkleid grün, Größe 38"
2025-08-16 19:42:31,858 [INFO] 4 imagen gefunden.
2025-08-16 19:42:31,966 [ERROR] FileNotFoundError: [Errno 2] No such file or directory: 'downloaded-ads/ad_3145748007/ad_3145748007__img1.jpg'

From the logs, we can see that the bot successfully logs in, scans the ads, and finds the items. However, the error occurs when it tries to download the first image of the first ad. The key part here is the FileNotFoundError with the path 'downloaded-ads/ad_3145748007/ad_3145748007__img1.jpg'. This strongly suggests that the directory or the image file itself is not being created or saved correctly.

Code of Conduct

The user has agreed to follow the project's Code of Conduct. Awesome! 👍

Analyzing the FileNotFoundError

Okay, let's dig deeper into this FileNotFoundError. It's crucial to understand why this file isn't being found. Here are some potential causes we need to investigate:

  1. Directory Creation: Is the downloaded-ads/ad_3145748007 directory being created before the bot tries to save the image? If the directory doesn't exist, the save operation will fail.
  2. File Saving Logic: Is there a bug in the code that handles saving the images? Maybe there's a typo in the file path, or the bot is trying to save the file before it's fully downloaded.
  3. Permissions: Does the bot have the necessary permissions to write files to the downloaded-ads directory? This is especially important on MacOS, where permissions can be a bit strict. 🔐
  4. Race Condition: Could there be a race condition where the bot is trying to save the image before the directory creation is complete? This is less likely, but still worth considering.
  5. Configuration Issues: Is there a configuration setting that might be affecting the download path or behavior? We should check the config.yaml file that the user mentioned in the logs.

Troubleshooting Steps

To get to the bottom of this, we need to try a few things:

  1. Verify Directory Creation: We should add some logging to the code to check if the directory is being created before the image is saved. If it's not, we've found our culprit! 🕵️‍♀️
  2. Inspect File Saving Code: We need to carefully review the code that saves the images. Are the file paths being constructed correctly? Are there any error handling mechanisms in place?
  3. Check Permissions: We should make sure that the bot has write access to the downloaded-ads directory. We can try running the bot with elevated privileges to see if that fixes the issue (but this is just for testing purposes!).
  4. Reproduce the Issue: We need to try and reproduce the issue ourselves using the steps provided by the user. This will allow us to debug the code and see what's happening in real-time.
  5. Examine the config.yaml: We should take a look at the user's config.yaml file to see if there are any settings that might be causing this issue.

Potential Code Fixes

Based on our initial analysis, here are some potential code fixes we might need to implement:

  • Ensure Directory Exists: We can use Python's os.makedirs(path, exist_ok=True) to create the directory if it doesn't exist. The exist_ok=True flag will prevent an error if the directory already exists.
  • Double-Check File Paths: We should carefully review the code that constructs the file paths to make sure there are no typos or logical errors. 🧐
  • Add Error Handling: We can add try...except blocks around the file saving code to catch any exceptions and log them. This will give us more information about what's going wrong.
  • Implement Retries: If the file saving fails, we can try retrying the operation a few times. This might help with intermittent issues or race conditions.

Next Steps

Okay, guys, we've got a good understanding of the issue and some potential solutions. Here's what we should do next:

  1. Reproduce the Bug: We need to try and reproduce the bug locally using the user's steps. This is the most important step, as it will allow us to debug the code and see what's happening.
  2. Add Logging: We should add some logging to the code to help us diagnose the issue. Specifically, we should log whether the directory exists before saving the image and any exceptions that occur during the saving process.
  3. Test Potential Fixes: We can try implementing the code fixes we discussed earlier and see if they resolve the issue.
  4. Communicate with the User: We should keep the user updated on our progress and ask them for any additional information that might be helpful. 🗣️

Let's get to work and squash this bug! 🐛🔨

Code of Conduct

The user has agreed to follow the project's Code of Conduct.