Fixing Hugging Face Login Issue (504 Gateway Timeout & Invalid Token Error)
Issue
I was trying to log in to Hugging Face CLI, but I kept getting the following error:
pythonCopyEditrequests.exceptions.HTTPError: 504 Server Error: Gateway Time-out for url: https://huggingface.co/api/whoami-v2
Even after trying multiple fixes, the error persisted and eventually changed to:
pythonCopyEditrequests.exceptions.HTTPError: Invalid user token.
What I Tried (But Didn’t Work)
Logging in again using
huggingface-cli login
→ FailedUpgrading Hugging Face Hub (
pip install --upgrade huggingface_hub
) → No effectClearing cache & re-installing dependencies → Still the same error
Final Solution That Worked 🎯
After many attempts, the issue got fixed by setting up a virtual environment and reinstalling everything from scratch. Here’s what worked:
bashCopyEditpython -m venv hf_env
source hf_env/bin/activate # (Windows users: `hf_env\Scripts\activate`)
pip install huggingface_hub
huggingface-cli login
Why This Works?
A virtual environment creates an isolated Python environment, avoiding conflicts with existing dependencies.
If there’s an issue with your global Python installation, this helps bypass it.
It ensures a clean install of
huggingface_hub
without any corrupted files.
If you’re facing similar issues, try this approach and let me know if it works for you!