# API Token not being recognized

**URL:** <https://discuss.huggingface.co/t/api-token-not-being-recognized/156624>\
**Category:** Beginners\
**Created:** [May 24, 2025, 2:14pm UTC](https://discuss.huggingface.co/t/api-token-not-being-recognized/156624 "2025-05-24T14:14:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mj6ux](https://avatars.discourse-cdn.com/v4/letter/m/e79b87/32.png) [@mj6ux](https://discuss.huggingface.co/u/mj6ux)\
**Post date:** [May 24, 2025, 2:14pm UTC](https://discuss.huggingface.co/t/api-token-not-being-recognized/156624/1 "2025-05-24T14:14:52Z")

</div>

I am having difficulty logging into my account using huggingface-cli login, but my token is not being recognized as a valid token. I have created several new tokens but I’m still getting a permission denied error.

The specifics:

Traceback (most recent call last):  
File “/home/mj6ux/.conda/envs/coconut/lib/python3.12/site-packages/huggingface\_hub/utils/\_http.py”, line 409, in hf\_raise\_for\_status  
response.raise\_for\_status()  
File “/home/mj6ux/.conda/envs/coconut/lib/python3.12/site-packages/requests/models.py”, line 1024, in raise\_for\_status  
raise HTTPError(http\_error\_msg, response=self)  
requests.exceptions.HTTPError: 429 Client Error: Too Many Requests for url: [https://huggingface.co/api/whoami-v2](https://huggingface.co/api/whoami-v2)

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

Traceback (most recent call last):  
File “/home/mj6ux/.conda/envs/coconut/lib/python3.12/site-packages/huggingface\_hub/hf\_api.py”, line 1664, in whoami  
hf\_raise\_for\_status(r)  
File “/home/mj6ux/.conda/envs/coconut/lib/python3.12/site-packages/huggingface\_hub/utils/\_http.py”, line 481, in hf\_raise\_for\_status  
raise \_format(HfHubHTTPError, str(e), response) from e  
huggingface\_hub.errors.HfHubHTTPError: 429 Client Error: Too Many Requests for url: [https://huggingface.co/api/whoami-v2](https://huggingface.co/api/whoami-v2)

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

Traceback (most recent call last):  
File “/home/mj6ux/.conda/envs/coconut/bin/huggingface-cli”, line 8, in   
sys.exit(main())  
^^^^^^  
File “/home/mj6ux/.conda/envs/coconut/lib/python3.12/site-packages/huggingface\_hub/commands/huggingface\_cli.py”, line 57, in main  
service.run()  
File “/home/mj6ux/.conda/envs/coconut/lib/python3.12/site-packages/huggingface\_hub/commands/user.py”, line 153, in run  
login(  
File “/home/mj6ux/.conda/envs/coconut/lib/python3.12/site-packages/huggingface\_hub/utils/\_deprecation.py”, line 101, in inner\_f  
return f(\*args, \*\*kwargs)  
^^^^^^^^^^^^^^^^^^  
File “/home/mj6ux/.conda/envs/coconut/lib/python3.12/site-packages/huggingface\_hub/utils/\_deprecation.py”, line 31, in inner\_f  
return f(\*args, \*\*kwargs)  
^^^^^^^^^^^^^^^^^^  
File “/home/mj6ux/.conda/envs/coconut/lib/python3.12/site-packages/huggingface\_hub/\_login.py”, line 130, in login  
interpreter\_login(new\_session=new\_session)  
File “/home/mj6ux/.conda/envs/coconut/lib/python3.12/site-packages/huggingface\_hub/utils/\_deprecation.py”, line 101, in inner\_f  
return f(\*args, \*\*kwargs)  
^^^^^^^^^^^^^^^^^^  
File “/home/mj6ux/.conda/envs/coconut/lib/python3.12/site-packages/huggingface\_hub/utils/\_deprecation.py”, line 31, in inner\_f  
return f(\*args, \*\*kwargs)  
^^^^^^^^^^^^^^^^^^  
File “/home/mj6ux/.conda/envs/coconut/lib/python3.12/site-packages/huggingface\_hub/\_login.py”, line 290, in interpreter\_login  
\_login(token=token, add\_to\_git\_credential=add\_to\_git\_credential)  
File “/home/mj6ux/.conda/envs/coconut/lib/python3.12/site-packages/huggingface\_hub/\_login.py”, line 404, in \_login  
token\_info = whoami(token)  
^^^^^^^^^^^^^  
File “/home/mj6ux/.conda/envs/coconut/lib/python3.12/site-packages/huggingface\_hub/utils/\_validators.py”, line 114, in \_inner\_fn  
return fn(\*args, \*\*kwargs)  
^^^^^^^^^^^^^^^^^^^  
File “/home/mj6ux/.conda/envs/coconut/lib/python3.12/site-packages/huggingface\_hub/hf\_api.py”, line 1677, in whoami  
raise HTTPError(error\_message, request=e.request, response=e.response) from e  
requests.exceptions.HTTPError: Invalid user token.

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](https://discuss.huggingface.co/u/John6666)\
**Post date:** [May 24, 2025, 11:08pm UTC](https://discuss.huggingface.co/t/api-token-not-being-recognized/156624/2 "2025-05-24T23:08:08Z")

</div>

401 errors are usually caused by network errors or environment variables, but there seem to be rare cases like this.

> [@401 Error when trying to upload model from local machine](https://discuss.huggingface.co/t/401-error-when-trying-to-upload-model-from-local-machine/156020):
>
> Hello everyone, im currently training LLMs locally with the Unsloth framework. After training they provide a way to upload your model to the Huggingface Hub. model.push\_to\_hub\_gguf( “LuuWee/modelspacename”, # Change hf to your username! tokenizer, quantization\_method = [“q4\_k\_m”, “q8\_0”, “q5\_k\_m”,], token = “hf\_access\_token”, ) For it to upload you need to add your username and an Accesstoken in the request. This worked for me when i trained in Google Colab. I tried the same thing in my …

> [@Huggingface-cli login issue](https://discuss.huggingface.co/t/huggingface-cli-login-issue/136547/3):
>
> i seemed to have in ~/.netrc credentials for [huggingface.co](http://huggingface.co), which i think they might have overridden my Authorization header. a smiple rm ~/.netrc did the trick

> i seemed to have in `~/.netrc` credentials for [huggingface.co](http://huggingface.co), which i think they might have overridden my Authorization header.  
> a smiple `rm ~/.netrc` did the trick
