Skip to content

Commit

Permalink
Send bearer auth in LFS upload (#1906)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wauplin authored Dec 15, 2023
1 parent 2b95d2b commit 65b19d9
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/huggingface_hub/lfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@
from typing import TYPE_CHECKING, BinaryIO, Dict, Iterable, List, Optional, Tuple, TypedDict
from urllib.parse import unquote

from requests.auth import HTTPBasicAuth

from huggingface_hub.constants import ENDPOINT, HF_HUB_ENABLE_HF_TRANSFER, REPO_TYPES_URL_PREFIXES
from huggingface_hub.utils import get_session

from .utils import get_token_to_send, hf_raise_for_status, http_backoff, logging, tqdm, validate_hf_hub_args
from .utils import (
build_hf_headers,
hf_raise_for_status,
http_backoff,
logging,
tqdm,
validate_hf_hub_args,
)
from .utils.sha import sha256, sha_fileobj


Expand Down Expand Up @@ -149,15 +154,8 @@ def post_lfs_batch_info(
}
if revision is not None:
payload["ref"] = {"name": unquote(revision)} # revision has been previously 'quoted'
resp = get_session().post(
batch_url,
headers=LFS_HEADERS,
json=payload,
auth=HTTPBasicAuth(
"access_token",
get_token_to_send(token or True), # type: ignore # Token must be provided or retrieved
),
)
headers = {**LFS_HEADERS, **build_hf_headers(token=token or True)} # Token must be provided or retrieved
resp = get_session().post(batch_url, headers=headers, json=payload)
hf_raise_for_status(resp)
batch_info = resp.json()

Expand Down Expand Up @@ -236,7 +234,7 @@ def lfs_upload(operation: "CommitOperationAdd", lfs_batch_action: Dict, token: O
_validate_lfs_action(verify_action)
verify_resp = get_session().post(
verify_action["href"],
auth=HTTPBasicAuth(username="USER", password=get_token_to_send(token or True)), # type: ignore
headers=build_hf_headers(token=token or True),
json={"oid": operation.upload_info.sha256.hex(), "size": operation.upload_info.size},
)
hf_raise_for_status(verify_resp)
Expand Down

0 comments on commit 65b19d9

Please sign in to comment.