Huggingface-cli login issue

Firstly I apologize if it’s really basic or trivial, but I don’t seem to understand how to login
I’m trying to login with the huggingface-cli login and it keeps giving me the following

huggingface-cli login --token <THE_TOKEN>
The token has not been saved to the git credentials helper. Pass `add_to_git_credential=True` in this function directly or `--add-to-git-credential` if using via `huggingface-cli` if you want to set the git credential as well.
Traceback (most recent call last):
  File "/home/appsinacup/AlexStuff/ComfyUI/imgaienv/lib/python3.12/site-packages/huggingface_hub/utils/_http.py", line 406, in hf_raise_for_status
    response.raise_for_status()
  File "/home/appsinacup/AlexStuff/ComfyUI/imgaienv/lib/python3.12/site-packages/requests/models.py", line 1024, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://huggingface.co/api/whoami-v2

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/appsinacup/AlexStuff/ComfyUI/imgaienv/lib/python3.12/site-packages/huggingface_hub/hf_api.py", line 1633, in whoami
    hf_raise_for_status(r)
  File "/home/appsinacup/AlexStuff/ComfyUI/imgaienv/lib/python3.12/site-packages/huggingface_hub/utils/_http.py", line 477, in hf_raise_for_status
    raise _format(HfHubHTTPError, str(e), response) from e
huggingface_hub.errors.HfHubHTTPError: 401 Client Error: Unauthorized for url: https://huggingface.co/api/whoami-v2 (Request ID: Root=1-678e5498-0b3b190044e69e0613e6cff6;d4ef20db-e33b-42cc-ac5c-5643c9e9b530)

Invalid username or password.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/appsinacup/AlexStuff/ComfyUI/imgaienv/bin/huggingface-cli", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/appsinacup/AlexStuff/ComfyUI/imgaienv/lib/python3.12/site-packages/huggingface_hub/commands/huggingface_cli.py", line 57, in main
    service.run()
  File "/home/appsinacup/AlexStuff/ComfyUI/imgaienv/lib/python3.12/site-packages/huggingface_hub/commands/user.py", line 153, in run
    login(
  File "/home/appsinacup/AlexStuff/ComfyUI/imgaienv/lib/python3.12/site-packages/huggingface_hub/utils/_deprecation.py", line 101, in inner_f
    return f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/home/appsinacup/AlexStuff/ComfyUI/imgaienv/lib/python3.12/site-packages/huggingface_hub/utils/_deprecation.py", line 31, in inner_f
    return f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/home/appsinacup/AlexStuff/ComfyUI/imgaienv/lib/python3.12/site-packages/huggingface_hub/_login.py", line 126, in login
    _login(token, add_to_git_credential=add_to_git_credential)
  File "/home/appsinacup/AlexStuff/ComfyUI/imgaienv/lib/python3.12/site-packages/huggingface_hub/_login.py", line 404, in _login
    token_info = whoami(token)
                 ^^^^^^^^^^^^^
  File "/home/appsinacup/AlexStuff/ComfyUI/imgaienv/lib/python3.12/site-packages/huggingface_hub/utils/_validators.py", line 114, in _inner_fn
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "/home/appsinacup/AlexStuff/ComfyUI/imgaienv/lib/python3.12/site-packages/huggingface_hub/hf_api.py", line 1635, in whoami
    raise HTTPError(
requests.exceptions.HTTPError: Invalid user token. If you didn't pass a user token, make sure you are properly logged in by executing `huggingface-cli login`, and if you did pass a user token, double-check it's correct.

also the token seems to work when testing it with

curl -i https://huggingface.co/api/whoami-v2 \
  -H "Authorization: Bearer <THE TOKEN>"
HTTP/2 200
content-type: application/json; charset=utf-8
content-length: 382
date: Mon, 20 Jan 2025 14:08:15 GMT
x-powered-by: huggingface-moon
cross-origin-opener-policy: same-origin
referrer-policy: strict-origin-when-cross-origin
x-request-id: Root=1-678e58cf-35223b3a7ca3d73215320b2d
access-control-allow-origin: https://huggingface.co
vary: Origin
access-control-expose-headers: X-Repo-Commit,X-Request-Id,X-Error-Code,X-Error-Message,X-Total-Count,ETag,Link,Accept-Ranges,Content-Range,X-Xet-Access-Token,X-Xet-Token-Expiration,X-Xet-Refresh-Route,X-Xet-Cas-Url,X-Xet-Hash
etag: W/"17e-uXTz1hbj/22y/TAql9VBBdqElGo"
x-cache: Miss from cloudfront
via: 1.1 e76c434a546615d1c8c0e096c588e7d4.cloudfront.net (CloudFront)
x-amz-cf-pop: OTP50-P2
x-amz-cf-id: 4T2TKFmHXP4ma4JeDw0sy4znD0ocV6p9kuv31krBlI0z4kSYbEGaaQ==

{"type":"user","id":"63dcf661f37111482522cda7","name":"propolys","fullname":"Alex","email":"alexander_00012@yahoo.com","emailVerified":true,"canPay":false,"periodEnd":null,"isPro":false,"avatarUrl":"/avatars/eb4ec70ff9803cb66fab23117ff45b02.svg","orgs":[],"auth":{"type":"access_token","accessToken":{"displayName":"Comfyread","role":"read","createdAt":"2025-01-20T13:02:07.690Z"}}}

Thank you for any help, and sorry again if it’s a noob question

System info

- huggingface_hub version: 0.27.1
- Platform: Linux-6.8.0-51-generic-aarch64-with-glibc2.39
- Python version: 3.12.3
- Running in iPython ?: No
- Running in notebook ?: No
- Running in Google Colab ?: No
- Running in Google Colab Enterprise ?: No
- Token path ?: /home/appsinacup/.cache/huggingface/token
- Has saved token ?: False
- Configured git credential helpers:
- FastAI: N/A
- Tensorflow: N/A
- Torch: 2.6.0.dev20241224+cu126
- Jinja2: 3.1.3
- Graphviz: N/A
- keras: N/A
- Pydot: 3.0.3
- Pillow: 11.1.0
- hf_transfer: N/A
- gradio: N/A
- tensorboard: N/A
- numpy: 1.26.4
- pydantic: 2.10.3
- aiohttp: 3.11.10
- ENDPOINT: https://huggingface.co
- HF_HUB_CACHE: /home/appsinacup/.cache/huggingface/hub
- HF_ASSETS_CACHE: /home/appsinacup/.cache/huggingface/assets
- HF_TOKEN_PATH: /home/appsinacup/.cache/huggingface/token
- HF_STORED_TOKENS_PATH: /home/appsinacup/.cache/huggingface/stored_tokens
- HF_HUB_OFFLINE: False
- HF_HUB_DISABLE_TELEMETRY: False
- HF_HUB_DISABLE_PROGRESS_BARS: None
- HF_HUB_DISABLE_SYMLINKS_WARNING: False
- HF_HUB_DISABLE_EXPERIMENTAL_WARNING: False
- HF_HUB_DISABLE_IMPLICIT_TOKEN: False
- HF_HUB_ENABLE_HF_TRANSFER: False
- HF_HUB_ETAG_TIMEOUT: 10
- HF_HUB_DOWNLOAD_TIMEOUT: 10
1 Like

huggingface_hub is also the latest version, and the procedure doesn’t seem to be wrong. Even if the token itself is fine-grained rather than read or write, there shouldn’t be a problem with logging in…
If it’s an SSL error, the authentication by requests won’t go through either.
It’s not impossible that there is a common case where HF_TOKEN is set somewhere and that takes priority, but it’s not in the list of environment variables. What is this phenomenon…?:thinking:

i seemed to have in ~/.netrc credentials for huggingface.co, which i think they might have overridden my Authorization header.
a smiple rm ~/.netrc did the trick

2 Likes

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.