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

Add server message to HTTPError (if any) #1015

Merged
merged 2 commits into from
Aug 25, 2022

Conversation

Wauplin
Copy link
Contributor

@Wauplin Wauplin commented Aug 25, 2022

Related to #1012 and https://github.com/huggingface/moon-landing/issues/3703.

Now the error message returned by the server is added to the HTTPError. Example for a gated dataset:

from huggingface_hub import snapshot_download

snapshot_download(
    "sbrandeis/gated-fields",
    repo_type="dataset",
    use_auth_token="xxx",
)
Traceback (most recent call last):
  File "/Users/lucain/projects/huggingface/huggingface_hub/imtesting.py", line 3, in <module>
    snapshot_download(
  File "/Users/lucain/projects/huggingface/huggingface_hub/src/huggingface_hub/utils/_deprecation.py", line 93, in inner_f
    return f(*args, **kwargs)
  File "/Users/lucain/projects/huggingface/huggingface_hub/src/huggingface_hub/_snapshot_download.py", line 168, in snapshot_download
    repo_info = _api.repo_info(
  File "/Users/lucain/projects/huggingface/huggingface_hub/src/huggingface_hub/hf_api.py", line 1462, in repo_info
    return self.dataset_info(
  File "/Users/lucain/projects/huggingface/huggingface_hub/src/huggingface_hub/hf_api.py", line 1340, in dataset_info
    _raise_for_status(r)
  File "/Users/lucain/projects/huggingface/huggingface_hub/src/huggingface_hub/utils/_errors.py", line 169, in _raise_for_status
    raise e
  File "/Users/lucain/projects/huggingface/huggingface_hub/src/huggingface_hub/utils/_errors.py", line 131, in _raise_for_status
    response.raise_for_status()
  File "/Users/lucain/projects/huggingface/huggingface_hub/.venv310_no_ml/lib/python3.10/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://huggingface.co/api/datasets/sbrandeis/gated-fields/revision/main (Request ID: M9tpczsa85hzfImiSj3WX)

Access to dataset sbrandeis/gated-fields is restricted and you are not in the authorized list. Visit https://huggingface.co/datasets/sbrandeis/gated-fields to ask for access.

@SBrandeis @Pierrci how would you test that ? I wanted to create a gated repo on the staging platform but since it would be created by the user itself, the gate is automatically open. And as far as I understand, when we use the production server in the CI it's only for public and open repositories (no token).

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Aug 25, 2022

The documentation is not available anymore as the PR was closed or merged.

@codecov
Copy link

codecov bot commented Aug 25, 2022

Codecov Report

Merging #1015 (55a05a9) into main (3c2f0c2) will increase coverage by 0.04%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #1015      +/-   ##
==========================================
+ Coverage   81.41%   81.45%   +0.04%     
==========================================
  Files          31       31              
  Lines        3411     3419       +8     
==========================================
+ Hits         2777     2785       +8     
  Misses        634      634              
Impacted Files Coverage Δ
src/huggingface_hub/utils/_errors.py 94.36% <100.00%> (+0.71%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@Wauplin Wauplin merged commit 6173c38 into main Aug 25, 2022
@Wauplin Wauplin deleted the 1012-improve-error-message-on-gated-models branch August 25, 2022 15:32
Wauplin added a commit that referenced this pull request Aug 25, 2022
* hotfix to add server message to HTTPError if any

* add test to check added response
# 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.

3 participants