Skip to content

Commit

Permalink
Fix: refetch metadata on 416 error
Browse files Browse the repository at this point in the history
  • Loading branch information
eight04 committed Dec 23, 2024
1 parent ef9ef9b commit ab1be03
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions comiccrawler/grabber.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def do_request(s, url, proxies, retry, **kwargs):
except HTTPError as err:
if not err.response:
err.response = r
raise err
raise err
# 302 error without location header
if r.status_code == 302:
# pylint: disable=protected-access
Expand Down Expand Up @@ -172,7 +172,11 @@ def grabimg(*args, on_opened=None, tempfile=None, headers=None, **kwargs):
except (KeyError, ValueError) as err_no_content_range:
raise err from err_no_content_range
if content_range_max == loaded:
return ImgResult(err.response, tempfile=tempfile)
# NOTE: we create a new request for metadata since the server may return wrong metadata on 416 resopnses
h = headers.copy()
del h["Range"]
r = grabber(*args, headers=h, **kwargs, method="HEAD")
return ImgResult(r, tempfile=tempfile)
if content_range_max < loaded and tempfile:
# FIXME: this should not happen
Path(tempfile).unlink()
Expand Down

0 comments on commit ab1be03

Please sign in to comment.