{"record":{"id":"b4b2880451363c80","repo":"NanmiCoder/MediaCrawler","slug":"failed-to-save-img-type-image","errorCode":null,"errorMessage":"Failed to save {img_type} image","messagePattern":"Failed to save (.+?) image","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"tools/slider_util.py","lineNumber":79,"sourceCode":"                \"Accept-Language\": \"zh-CN,zh;q=0.9,en-GB;q=0.8,en;q=0.7,ja;q=0.6\",\n                \"AbstractCache-Control\": \"max-age=0\",\n                \"Connection\": \"keep-alive\",\n                \"Host\": urlparse(img).hostname,\n                \"Upgrade-Insecure-Requests\": \"1\",\n                \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) \"\n                              \"Chrome/91.0.4472.164 Safari/537.36\",\n            }\n            img_res = httpx.get(img, headers=headers)\n            if img_res.status_code == 200:\n                img_path = f'./temp_image/{img_type}.jpg'\n                image = np.asarray(bytearray(img_res.content), dtype=\"uint8\")\n                image = cv2.imdecode(image, cv2.IMREAD_COLOR)\n                if resize:\n                    image = cv2.resize(image, dsize=resize)\n                cv2.imwrite(img_path, image)\n                return img_path\n            else:\n                raise Exception(f\"Failed to save {img_type} image\")\n        else:\n            return img\n\n    @staticmethod\n    def clear_white(img):\n        \"\"\"Clear whitespace from image, mainly clearing slider whitespace\"\"\"\n        img = cv2.imread(img)\n        rows, cols, channel = img.shape\n        min_x = 255\n        min_y = 255\n        max_x = 0\n        max_y = 0\n        for x in range(1, rows):\n            for y in range(1, cols):\n                t = set(img[x, y])\n                if len(t) >= 2:\n                    if x <= min_x:\n                        min_x = x","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/NanmiCoder/MediaCrawler/blob/d6f7c5bb906b6dac40ddf343ef9e26438a3de092/tools/slider_util.py#L61-L97","documentation":"Error \"Failed to save {img_type} image\" thrown in NanmiCoder/MediaCrawler.","triggerScenarios":"Thrown at tools/slider_util.py:79 when the library encounters an invalid state.","commonSituations":"The slider/captcha image download (httpx.get) returned a non-200 status, so the image could not be written to ./temp_image/. Causes: expired captcha image URL, anti-bot rejection of the plain httpx request despite browser-like headers, or network failure. Defensive fix: validate status and content-type before decoding with cv2.imdecode, ensure the ./temp_image directory exists, and surface the status code in the exception message.","solutions":["Check that the ./temp_image directory exists and is writable; create it before downloading slider images.","Verify the image URL is reachable and returns HTTP 200; retry on transient network errors.","Ensure the request headers (Host, User-Agent) match the image host's expectations; some CDN hosts reject mismatched headers.","Confirm opencv (cv2) can decode the downloaded bytes; if the response is an error page rather than an image, the decode/write will fail."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"d6f7c5bb906b6dac40ddf343ef9e26438a3de092","analyzedAt":"2026-08-15T01:39:07.505Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}