Skip to content

Commit

Permalink
Fix: handle 416 content-range
Browse files Browse the repository at this point in the history
  • Loading branch information
eight04 committed Aug 15, 2024
1 parent 2298ab1 commit 1021b2a
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion comiccrawler/grabber.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,21 @@ def grabimg(*args, on_opened=None, tempfile=None, header=None, **kwargs):
if not header:
header = {}
header["Range"] = f"bytes={loaded}-"
r = grabber(*args, header=header, **kwargs)
try:
r = grabber(*args, header=header, **kwargs)
except requests.HTTPError as err:
if err.response.status_code != 416:
raise err
try:
content_range_max = int(err.response.headers["Content-Range"].split("/")[-1])
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)
if content_range_max < loaded and tempfile:
# FIXME: this should not happen
Path(tempfile).unlink()
raise err
if on_opened:
on_opened(r)
if r.status_code == 200:
Expand Down

0 comments on commit 1021b2a

Please sign in to comment.