Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Better error message for bad token. #362

Merged
merged 1 commit into from
Sep 21, 2021
Merged

Better error message for bad token. #362

merged 1 commit into from
Sep 21, 2021

Conversation

sgugger
Copy link
Contributor

@sgugger sgugger commented Sep 21, 2021

When a user passed a bad token to create a Repository, it ends up with a bit of cryptic error in HfApi.whoami:

Traceback (most recent call last):
  File "examples/pytorch/text-classification/run_glue_no_trainer.py", line 488, in <module>
    main()
  File "examples/pytorch/text-classification/run_glue_no_trainer.py", line 203, in main
    repo_name = get_full_repo_name(Path(args.output_dir).name, token=args.hub_token)
  File "/home/sgugger/git/transformers/src/transformers/file_utils.py", line 2249, in get_full_repo_name
    username = HfApi().whoami(token)["name"]
  File "/home/sgugger/git/huggingface_hub/src/huggingface_hub/hf_api.py", line 330, in whoami
    r.raise_for_status()
  File "/home/sgugger/.pyenv/versions/3.7.9/envs/base/lib/python3.7/site-packages/requests/models.py", line 941, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://huggingface.co/api/whoami-v2

This PR addresses that by writing a more helpful error message.

@sgugger sgugger requested a review from LysandreJik September 21, 2021 15:41
Copy link
Member

@LysandreJik LysandreJik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonderful, thank you for taking care of it! LGTM

@LysandreJik LysandreJik merged commit b1df674 into main Sep 21, 2021
@LysandreJik LysandreJik deleted the auth_error branch September 21, 2021 15:42
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants