Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 403 error handling in upload #22

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 43 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,48 @@ 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}. Retrying with description as title.")
new_md["description"] = md["title"]
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 again for {remote_identifier}. Retrying with empty description.")
new_md["description"] = ""
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 again for {remote_identifier}. No more retries will be attempted.")
else:
raise e
else:
raise e
else:
raise e

with open(
f"{videos_basepath}/{local_identifier}/_uploaded.mark",
"w",
Expand Down
Loading