Skip to content

Commit a7ee9ed

Browse files
surface 401 unauthorized errors more directly in snapshot_download (#3092)
1 parent 7a45b41 commit a7ee9ed

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/huggingface_hub/_snapshot_download.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@
77
from tqdm.contrib.concurrent import thread_map
88

99
from . import constants
10-
from .errors import GatedRepoError, LocalEntryNotFoundError, RepositoryNotFoundError, RevisionNotFoundError
10+
from .errors import (
11+
GatedRepoError,
12+
HfHubHTTPError,
13+
LocalEntryNotFoundError,
14+
RepositoryNotFoundError,
15+
RevisionNotFoundError,
16+
)
1117
from .file_download import REGEX_COMMIT_HASH, hf_hub_download, repo_folder_name
1218
from .hf_api import DatasetInfo, HfApi, ModelInfo, SpaceInfo
1319
from .utils import OfflineModeIsEnabled, filter_repo_objects, logging, validate_hf_hub_args
@@ -228,8 +234,10 @@ def snapshot_download(
228234
"outgoing traffic has been disabled. To enable repo look-ups and downloads online, set "
229235
"'HF_HUB_OFFLINE=0' as environment variable."
230236
) from api_call_error
231-
elif isinstance(api_call_error, RepositoryNotFoundError) or isinstance(api_call_error, GatedRepoError):
232-
# Repo not found => let's raise the actual error
237+
elif isinstance(api_call_error, (RepositoryNotFoundError, GatedRepoError)) or (
238+
isinstance(api_call_error, HfHubHTTPError) and api_call_error.response.status_code == 401
239+
):
240+
# Repo not found, gated, or specific authentication error => let's raise the actual error
233241
raise api_call_error
234242
else:
235243
# Otherwise: most likely a connection issue or Hub downtime => let's warn the user

0 commit comments

Comments
 (0)