NanmiCoder/MediaCrawler · error · Exception
Failed to save {img_type} image
Error message
Failed to save {img_type} image What it means
Error "Failed to save {img_type} image" thrown in NanmiCoder/MediaCrawler.
Source
Thrown at tools/slider_util.py:79
"Accept-Language": "zh-CN,zh;q=0.9,en-GB;q=0.8,en;q=0.7,ja;q=0.6",
"AbstractCache-Control": "max-age=0",
"Connection": "keep-alive",
"Host": urlparse(img).hostname,
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/91.0.4472.164 Safari/537.36",
}
img_res = httpx.get(img, headers=headers)
if img_res.status_code == 200:
img_path = f'./temp_image/{img_type}.jpg'
image = np.asarray(bytearray(img_res.content), dtype="uint8")
image = cv2.imdecode(image, cv2.IMREAD_COLOR)
if resize:
image = cv2.resize(image, dsize=resize)
cv2.imwrite(img_path, image)
return img_path
else:
raise Exception(f"Failed to save {img_type} image")
else:
return img
@staticmethod
def clear_white(img):
"""Clear whitespace from image, mainly clearing slider whitespace"""
img = cv2.imread(img)
rows, cols, channel = img.shape
min_x = 255
min_y = 255
max_x = 0
max_y = 0
for x in range(1, rows):
for y in range(1, cols):
t = set(img[x, y])
if len(t) >= 2:
if x <= min_x:
min_x = xView on GitHub (pinned to d6f7c5bb90)
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.
When it happens
Trigger: Thrown at tools/slider_util.py:79 when the library encounters an invalid state.
Common situations: 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.
AI-assisted analysis of NanmiCoder/MediaCrawler@d6f7c5bb90 (2026-08-15).
Data as JSON: /api/errors/b4b2880451363c80.
Report an issue: GitHub.