Skip to content

Commit

Permalink
Better error message for bad token. (#362)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgugger authored Sep 21, 2021
1 parent e90b593 commit b1df674
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/huggingface_hub/hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,13 @@ def whoami(self, token: str) -> Dict:
"""
path = "{}/api/whoami-v2".format(self.endpoint)
r = requests.get(path, headers={"authorization": "Bearer {}".format(token)})
r.raise_for_status()
try:
r.raise_for_status()
except HTTPError as e:
raise 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."
) from e
return r.json()

def logout(self, token: str) -> None:
Expand Down

0 comments on commit b1df674

Please # to comment.