Skip to content

Commit

Permalink
Fix 403 error handling in upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Ovler-Young committed Nov 22, 2024
1 parent e004fe0 commit b169b02
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions biliarchiver/_biliarchiver_upload_bvid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit b169b02

Please sign in to comment.