Can't login to Huggingface CLI

I am trying to login to huggingface-cli using:

huggingface-cli login

and keep getting this error:

Traceback (most recent call last):
  File "/pfss/mlde/workspaces/mlde_wsp_Rohrbach/users/ns94feza/.conda/envs/llmonk2/bin/huggingface-cli", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/pfss/mlde/workspaces/mlde_wsp_Rohrbach/users/ns94feza/.conda/envs/llmonk2/lib/python3.11/site-packages/huggingface_hub/commands/huggingface_cli.py", line 57, in main
    service.run()
  File "/pfss/mlde/workspaces/mlde_wsp_Rohrbach/users/ns94feza/.conda/envs/llmonk2/lib/python3.11/site-packages/huggingface_hub/commands/user.py", line 98, in run
    login(token=self.args.token, add_to_git_credential=self.args.add_to_git_credential)
  File "/pfss/mlde/workspaces/mlde_wsp_Rohrbach/users/ns94feza/.conda/envs/llmonk2/lib/python3.11/site-packages/huggingface_hub/_login.py", line 115, in login
    interpreter_login(new_session=new_session, write_permission=write_permission)
  File "/pfss/mlde/workspaces/mlde_wsp_Rohrbach/users/ns94feza/.conda/envs/llmonk2/lib/python3.11/site-packages/huggingface_hub/_login.py", line 194, in interpreter_login
    _login(token=token, add_to_git_credential=add_to_git_credential, write_permission=write_permission)
  File "/pfss/mlde/workspaces/mlde_wsp_Rohrbach/users/ns94feza/.conda/envs/llmonk2/lib/python3.11/site-packages/huggingface_hub/_login.py", line 307, in _login
    raise ValueError("Invalid token passed!")
ValueError: Invalid token passed!

I have tried pasting via a right-click instead of cmd+v but that didn’t work. This token has worked in the past, and I have tried using a fresh token as well, but nothing has worked so far.

For context, I recently got rate limited while trying to upload some data, so I’m wondering if that caused this issue. Is there a way to lift the limit? it’s been a few hours since it was applied.

@Wauplin I was wondering if you could somehow help here

1 Like

Hey @nishadsinghi,
Can you maybe try logging in by passing the token directly as a flag in the terminal:

huggingface-cli login --token hf_yourtoken

If this doesn’t resolve the issue, you can try some other discussed solutions in a similar discussion in (@ How to login to Huggingface Hub with Access Token). Let me know if this helps! If the issue persists, feel free to update here.

1 Like

Hi @nnilayy, thanks for replying!

  1. I tried huggingface-cli login --token my_token and got the same error.
  2. I tried the tips from the link you shared (like pasting the token using the mouse instead of cmd+v) and that doesn’t work either.
    Let me know if you have any other suggestions!
1 Like

It seems that there are also cases where the cause is something else.

1 Like

Hey @John6666, thanks for your reply :slight_smile: Like I said, I’ve already tried alternative ways of pasting the token, but so far nothing has worked.

1 Like

It’s not just because of the token, but it seems to happen for other reasons too, such as an old version of git itself… As a result, it cannot interpret the tokens.
This happens particularly on Windows.

1 Like

Hey @nishadsinghi,
Another workaround that seems to work on my end is using a notebook to log in within the same environment where huggingface_hub[cli] is installed. You can try running the following in a .ipynb notebook and paste your token into the displayed textbox:

from huggingface_hub import login
login()

After entering your token, check if you’re successfully logged in by running the following in a terminal:

huggingface-cli whoami  

If it displays your Hugging Face username, the login was successful.

Additionally, as @John6666 pointed out, outdated versions of Git can also lead to silent issues. You can check your Git version with:

git --version

If it’s an older version, updating it might help. You can update Git using:

git update

After this, try logging in again using the different methods discussed earlier. Let us know if it works or if you’re still facing issues!

1 Like

Hi @nnilayy, thanks for the suggestions. I tried logging in through a notebook but still got the same error.
I am using this on a cluster, and I think updating git requires sudo access, so I couldn’t do it. I have a feeling that this is not the root cause of the issue, since things were working fine until recently (but I could be wrong).

1 Like

Maybe cluster is suspicious. But for example, there are often cases where authentication fails due to SSL settings, but in that case, the error message shouldn’t be that…
So I’m confused.

1 Like

Is there a way to check the rate limits? I’ve contacted HF via email but haven’t heard back :confused:

1 Like

Hi @nishadsinghi sorry for the inconvenience. Could you try to login using a script just to be 100% sure it’s not a encoding issue with the terminal:

from huggingface_hub import login, whoami

login(token="hf_....")
whoami()

Also, could you install huggingface_hub from source (see install steps) and retry? We’ve recently pushed a small feature that tells you which token has been used when whoami fails. Sometimes it can be due to an environement vairable (HF_TOKEN) mixing with the locally saved one.


Note: huggingface_hub/huggingface-cli are only using HTTP calls and are completely separated from git. There is nothing you can do on the git side that breaks huggingface-cli (and therefore nothing you can do to fix it using git)

2 Likes

Hey @Wauplin, thanks for getting back to me. I followed these steps:

  1. Created a fresh conda environment, and installed HF hub from source using:
pip install git+https://github.com/huggingface/huggingface_hub
  1. Created a script with the contents you posted.
  2. Ran the python script from step 2.

And I still get the same ‘Invalid token’ error.
Just for context, I am doing all of this on a remote cluster.
I also tried to login on my local machine using the same token and that works, so the token is not the issue.

1 Like