Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix error message if invalid token on file download #2847

Merged
merged 1 commit into from
Feb 11, 2025

Conversation

Wauplin
Copy link
Contributor

@Wauplin Wauplin commented Feb 10, 2025

Related to huggingface/transformers#36104.

Since recently, when a user tries to download a file with an invalid token, the download fails with a 401 error "Invalid credentials in Authorization header" even if the repo is public. At the moment, this results in a RepoNotFound error raised in huggingface_hub, similar to if the repo is private or gated. With this PR, the error message should be less confusing.

Previously:

(...)
  File "/home/wauplin/projects/huggingface_hub/src/huggingface_hub/file_download.py", line 302, in _request_wrapper
    hf_raise_for_status(response)
  File "/home/wauplin/projects/huggingface_hub/src/huggingface_hub/utils/_http.py", line 457, in hf_raise_for_status
    raise _format(RepositoryNotFoundError, message, response) from e
huggingface_hub.errors.RepositoryNotFoundError: 401 Client Error. (Request ID: Root=1-67aa2e37-20b8c3033faef2da3677b130;875cea10-0550-4ba6-8c74-87fd52d8880f)

Repository Not Found for url: https://huggingface.co/openai-community/gpt2/resolve/main/config.json.
Please make sure you specified the correct `repo_id` and `repo_type`.
If you are trying to access a private or gated repo, make sure you are authenticated.
Invalid credentials in Authorization header

With this PR:

(...)
  File "/home/wauplin/projects/huggingface_hub/src/huggingface_hub/file_download.py", line 303, in _request_wrapper
    hf_raise_for_status(response)
  File "/home/wauplin/projects/huggingface_hub/src/huggingface_hub/utils/_http.py", line 481, in hf_raise_for_status
    raise _format(HfHubHTTPError, str(e), response) from e
huggingface_hub.errors.HfHubHTTPError: 401 Client Error: Unauthorized for url: https://huggingface.co/openai-community/gpt2/resolve/main/config.json (Request ID: Root=1-67aa2e15-52cc487054e9c9942e946343;b5eb54d7-cf40-49ca-a69d-8da35d4c5e4a)

Invalid credentials in Authorization header

(related slack thread - internal link)

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Member

@Rocketknight1 Rocketknight1 left a comment

Choose a reason for hiding this comment

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

Thanks for the quick fix!

Copy link
Contributor

@hanouticelina hanouticelina left a comment

Choose a reason for hiding this comment

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

thank you @Wauplin!

@Wauplin Wauplin merged commit fc491d4 into main Feb 11, 2025
17 checks passed
@Wauplin Wauplin deleted the fix-error-message-if-invalid-token-on-file-download branch February 11, 2025 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants