How My Metadata Script Skips Bad Files Instead Of Crashing A 300-File Run
说明与用途
元数据脚本处理300个文件,但在遇到零字节图像时崩溃,导致CSV不完整。通过对每个文件进行验证并使用try/except包装处理,它现在会跳过损坏的文件,记录错误,并输出干净的CSV,避免账户被标记。
问题
A zero‑byte JPG caused a metadata script to crash, producing an incomplete CSV and no error log.
结果
The updated script processes all valid files, logs errors, and produces a clean CSV, preventing account flagging due to partial uploads.
工作流
- 1. Validate file existence, size, and extension before processing.
- 2. Wrap per‑file processing in try/except to catch errors.
- 3. On failure, write filename and reason to errors.log and continue.
- 4. After loop, output CSV with only valid rows and a summary of successes and failures.
- 5. Use upload_tracker.py to track processed files and avoid double‑posting.
证据
Around file 84 the script hit a zero-byte JPG that a render subprocess had left behind, threw on Image.open(), and died.
Now every file goes through its own try/except, and a failure writes one line to errors.log with the filename and the reason, then moves on.
The second version of the script wrote rows first and hoped. Now it checks each file before a row gets built: does the file exist, is it non-zero bytes, does the extension match what I passed with --ext, can the title be derived.
- 记录日期: 2026-10-22T11:26:07.100Z