From fe63c823e36d89e6e33da3b298ec1ddee81aa0f8 Mon Sep 17 00:00:00 2001 From: ytshen Date: Thu, 26 Dec 2024 23:06:08 +0800 Subject: [PATCH] ignore file download if 404 not found --- main.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index acb5d0b..e60831b 100644 --- a/main.py +++ b/main.py @@ -25,11 +25,12 @@ def download_xpi(xpi_url: str, download_dir: str, unique_name: str, force_downlo return download_filepath response = requests.get(xpi_url, stream=True) - print(f'download {unique_name} from {xpi_url}') - with open(download_filepath, "wb") as file: - for chunk in response.iter_content(chunk_size=1024): - file.write(chunk) - return download_filepath + if response.status_code == 200: + print(f'download {unique_name} from {xpi_url}') + with open(download_filepath, "wb") as file: + for chunk in response.iter_content(chunk_size=1024): + file.write(chunk) + return download_filepath except Exception as e: print(f'download {unique_name} from {xpi_url} failed: {e}')