How to login to Huggingface Hub with Access Token

Hello and thank you! I looked up this issue but I keep getting topics about ‘tokenizer’ and did not find anything on using access tokens.

I simply want to login to Huggingface HUB using an access token. I signed up, read the card, accepted its terms by checking the box, setup a conda env, installed huggingface-cli, and then executed huggingface-cli login. When I try and paste my access token (I have tried both read and write) it gives me the following error:

Traceback (most recent call last):
  File "C:\Users\mrlor\anaconda3\envs\ldm\Scripts\huggingface-cli-script.py", line 9, in <module>
    sys.exit(main())
  File "C:\Users\mrlor\anaconda3\envs\ldm\lib\site-packages\huggingface_hub\commands\huggingface_cli.py", line 41, in main
    service.run()
  File "C:\Users\mrlor\anaconda3\envs\ldm\lib\site-packages\huggingface_hub\commands\user.py", line 176, in run
    _login(self._api, token=token)
  File "C:\Users\mrlor\anaconda3\envs\ldm\lib\site-packages\huggingface_hub\commands\user.py", line 343, in _login
    token, name = hf_api._validate_or_retrieve_token(token)
  File "C:\Users\mrlor\anaconda3\envs\ldm\lib\site-packages\huggingface_hub\hf_api.py", line 691, in _validate_or_retrieve_token
    raise ValueError("Invalid token passed!")
ValueError: Invalid token passed!

I have also tried typing in the access token by hand. I have deleted and created new access tokens. I also have git lfs setup. I restarted my computer and have updated my conda environment. I am sure this is something silly but I have been trying for hours to login with no avail. I thank you for your help!

3 Likes

Facing same issue. Any resolution?

1 Like

No, I have not heard from anyone and still can not login.

For what it’s worth, I’ve been doing it like this in my scripts:

pip install huggingface_hub
python -c "from huggingface_hub.hf_api import HfFolder; HfFolder.save_token('MY_HUGGINGFACE_TOKEN_HERE')"

Not sure if it’s as convenient as pasting your token, but it might work.

UPDATE: Oh I just realized you are on Windows. I guess my advice might not apply, since I don’t know how to pass code in the command line in Windows. But in general, I guess try using Python to do the login?

15 Likes

I have the same issue, when i enter or paste the string, nothing happens on the coursor, like all my input gets blocked, yes im also on windows:

hoping for help :slight_smile:

2 Likes

So what ended up working for me was instead of using Ctrl+V to paste the access token I right-clicked on the command line and it pasted it. Note that you still won’t see anything on the ‘Token:’ line but it is should be there. Hope this helps!!

7 Likes

I cant yet. I have the same problem. I right clicked before to verify that it copied it and if it was pasted, then I used huggingface-cli login, Enter, right click on the command line and enter and nothing. It won’t let me write either. :frowning:

How do you even right click? I can’t right click on anaconda prompt :confused:

2 Likes

I wasn’t able to create my token with a username or my name so I tried my email registered to huggingface. I used the right click to paste function and it worked. Hope that helps

Even when I paste the token into the command line, it calls the token invalid

EDIT: I did it several times in a row and it finally worked, don’t know how.

i just have to come here and say that:

  1. run the command prompt as admin
  2. copy your token in
  3. wait about 5 minutes
  4. run huggingface-cli login
  5. right-click the top bar of the command line window, go to “Edit”, and then Paste
  6. it should work. IF IT DOESN’T WORK, DO IT UNTIL IT DOES.
5 Likes

Thank you all for posting your tricks for logging in! It seems that using hotkeys to paste in the token DOES NOT work (in Windows) so you will have to resort to right-clicking to paste in your token or using Edit->Paste from the toolbar. Note again that you will not see the token on the command line and will not see asterixis in its place; it will appear completely invisible but will be submitted after your press enter.

Same issue. "ValueError: Invalid token passed! in powershell with correct toket right clicked (at top) and pasted in. I even cleared my token and tried a fresh one…no luck.

2 Likes

Nevermind. Right click edit paste worked. You just won’t see any indication you put in the key. Then press enter. I was probably pasting multiple times or something stupid as the key input field would not show any change but just blink even with the key put it. Anyhoo, it works.

2 Likes

In the anaconda prompt, just the act of right-clicking will paste your item. I got mine to work by copying the token, typing: huggingface-cli login into the anaconda prompt, literally just right-clicking on the window, and pressing enter.

Also, another way to go is to go to your “\virtualenv\Lib\site-packages\huggingface_hub\commands” folder and there is a file in there called “user” or “userpy”. Edit the file and go to the area in the middle that looks like the huggingface login. The line should say token = getpass ("Token: ") Change this line to say token = “this is where your hugging face token goes including the quotation marks#getpass("Token: ")

save file then run huggingface-cli login

2 Likes

If you are using anaconda prompt and is having [WinError 2] File Not Found issue, try to install git first using the following command,

conda install -c anaconda git

1 Like

thanks for this! this worked for me :slight_smile:

It looks like pasting the token actually works fine for me. The problem is just that the login screen doesn’t show any visual indication that it does! So, just use whatever way you normally paste text onto your terminal screen on this login screen and hit Enter, and it’ll work. Seems like a very trivial fix on the login screen to at least shows dots in-place once the pasted text is entered.

same for me, this seems to be the problem