From b169b021442408d6f6a5894c4a3d97477e303fd4 Mon Sep 17 00:00:00 2001 From: Ovler Date: Fri, 22 Nov 2024 18:09:44 -0500 Subject: [PATCH] Fix 403 error handling in upload --- biliarchiver/_biliarchiver_upload_bvid.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/biliarchiver/_biliarchiver_upload_bvid.py b/biliarchiver/_biliarchiver_upload_bvid.py index 163fd44..92dfdab 100644 --- a/biliarchiver/_biliarchiver_upload_bvid.py +++ b/biliarchiver/_biliarchiver_upload_bvid.py @@ -5,7 +5,7 @@ from typing import List from urllib.parse import urlparse from internetarchive import get_item -from requests import Response +from requests import Response, HTTPError from rich import print from pathlib import Path from shutil import rmtree @@ -287,13 +287,20 @@ def _upload_bvid( print("Removed XML illegal characters from metadata, cleaned metadata:") print(new_md) - r = item.modify_metadata( - metadata=new_md, - access_key=access_key, - secret_key=secret_key, - ) - assert isinstance(r, Response) - r.raise_for_status() + try: + r = item.modify_metadata( + metadata=new_md, + access_key=access_key, + secret_key=secret_key, + ) + assert isinstance(r, Response) + r.raise_for_status() + except HTTPError as e: + if e.response.status_code == 403: + print(f"403 Forbidden error encountered for {remote_identifier}. No retries will be attempted.") + else: + raise e + with open( f"{videos_basepath}/{local_identifier}/_uploaded.mark", "w",