Skip to content

Commit

Permalink
Merge pull request #5 from ToshY/bug/download-except-handler
Browse files Browse the repository at this point in the history
changed to HTTPError for exception handler and time sleep fix
  • Loading branch information
ToshY authored Dec 19, 2022
2 parents d8e3e95 + 569f3fb commit 26feb38
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
import argparse
import os
import sys
import time
import logging as log
import shutil
import urllib.request
import urllib.error
from time import time, sleep
from base64 import b64encode
from time import time
from slugify import slugify
from src.banner import cli_banner

Expand Down Expand Up @@ -142,14 +141,14 @@ def download_helper(image_url, file_path) -> None:

log.info("Saved file to `%s`", file_path)
return
except urllib.error.URLError as http_exception:
except urllib.error.HTTPError as http_exception:
retry_count = retry_count - 1
log.warning(
"Error response when sending request: `%s`; Retrying `%s` more times...",
http_exception,
retry_count,
)
time.sleep(pow(2, retry_count))
sleep(pow(2, retry_count))
continue

if retry_count == 0 and len(http_exception) != 0:
Expand Down

0 comments on commit 26feb38

Please sign in to comment.