huggingface / huggingface_hub

The official Python client for the Huggingface Hub.
https://huggingface.co/docs/huggingface_hub
Apache License 2.0
1.82k stars 470 forks source link

400: Bad Request when accessing a space #2357

Closed ademait closed 5 days ago

ademait commented 5 days ago

Describe the bug

Hi everyone,

When I try to get the space runtime or space info with:

runtime = api.get_space_runtime(space.id, token=ACCESS_TOKEN)
space_info = api.repo_info(space.id, repo_type="space")

It throws a huggingface_hub.utils._errors.BadRequestError with a body: """ Bad request: "metadata" is required """ I have checked on the website that the repositories that throw this error also show a 400 bad request in the website (check here). It happened to a few repositories, I can share the list.

On the other side, I tried to catch the huggingface_hub.utils._errors.BadRequestError with:

from huggingface_hub.utils._errors import BadRequestError
try:
....
except BadRequestError as badreq_err:
....

but it doesn't catch the exception. Am I properly importing the error? Is it because it throws an HTTPError instead of BadRequestError?

Reproduction

from huggingface_hub import HfApi

api = HfApi() space_id = "WitchHuntTV/WinnieThePoohSVC_sovits4"

runtime = api.get_space_runtime(space_id)

Logs

---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
File ~/anaconda3/envs/hf/lib/python3.9/site-packages/huggingface_hub/utils/_errors.py:304, in hf_raise_for_status(response, endpoint_name)
    303 try:
--> 304     response.raise_for_status()
    305 except HTTPError as e:

File ~/anaconda3/envs/hf/lib/python3.9/site-packages/requests/models.py:1021, in Response.raise_for_status(self)
   1020 if http_error_msg:
-> 1021     raise HTTPError(http_error_msg, response=self)

HTTPError: 400 Client Error: Bad Request for url: https://huggingface.co/api/spaces/WitchHuntTV/WinnieThePoohSVC_sovits4/runtime

The above exception was the direct cause of the following exception:

BadRequestError                           Traceback (most recent call last)
Cell In[4], line 6
      3 api = HfApi()
      4 space_id = "WitchHuntTV/WinnieThePoohSVC_sovits4"
----> 6 runtime = api.get_space_runtime(space_id)

File ~/anaconda3/envs/hf/lib/python3.9/site-packages/huggingface_hub/utils/_validators.py:114, in validate_hf_hub_args.<locals>._inner_fn(*args, **kwargs)
    111 if check_use_auth_token:
    112     kwargs = smoothly_deprecate_use_auth_token(fn_name=fn.__name__, has_token=has_token, kwargs=kwargs)
--> 114 return fn(*args, **kwargs)
...

BadRequestError:  (Request ID: Root=1-667e4ffb-30383f4f289a640224913112;012d2be1-3365-4977-b710-e110f2154801)

Bad request:
"metadata" is required

System info

- huggingface_hub version: 0.23.4
- Platform: Linux-6.2.16-4-pve-x86_64-with-glibc2.28
- Python version: 3.9.12
- Running in iPython ?: Yes
- iPython shell: ZMQInteractiveShell
- Running in notebook ?: Yes
- Running in Google Colab ?: No
- Token path ?: /root/.cache/huggingface/token
- Has saved token ?: False
- Configured git credential helpers: 
- FastAI: N/A
- Tensorflow: N/A
- Torch: N/A
- Jinja2: 3.1.2
- Graphviz: N/A
- keras: N/A
- Pydot: N/A
- Pillow: N/A
- hf_transfer: N/A
- gradio: N/A
- tensorboard: N/A
- numpy: N/A
- pydantic: N/A
- aiohttp: N/A
- ENDPOINT: https://huggingface.co
- HF_HUB_CACHE: /root/.cache/huggingface/hub
- HF_ASSETS_CACHE: /root/.cache/huggingface/assets
- HF_TOKEN_PATH: /root/.cache/huggingface/token
- HF_HUB_OFFLINE: False
- HF_HUB_DISABLE_TELEMETRY: False
- HF_HUB_DISABLE_PROGRESS_BARS: None
- HF_HUB_DISABLE_SYMLINKS_WARNING: False
- HF_HUB_DISABLE_EXPERIMENTAL_WARNING: False
- HF_HUB_DISABLE_IMPLICIT_TOKEN: False
- HF_HUB_ENABLE_HF_TRANSFER: False
- HF_HUB_ETAG_TIMEOUT: 10
- HF_HUB_DOWNLOAD_TIMEOUT: 10
Wauplin commented 5 days ago

Hi @ademait, thanks for reporting! This Space has been disabled by an admin, which created some side effect on the API. This should now be fixed (at least gives more explicit error). See:

Wauplin commented 5 days ago

Btw, it's best to catch huggingface_hub.utils._errors.HfHubHTTPError is this case. It's a subclass of HTTPError with more precise information. It's raised by huggingface_hub.urils.hf_raise_for_status.

ademait commented 3 days ago

Hi @Wauplin , thank you for the fast reply! I have found another spaces with the same issues, I could share the names here

Wauplin commented 3 days ago

Hi @ademait, that would be helpful if you could yes. Thanks in advance!

ademait commented 1 day ago

Hi @Wauplin , the spaces that gave me the very same error are: "qandeelfatima/ImageToText", "lunarflu/test2","fastaioncampus/Classificador-de-carros","xzkqaq/1". I hope it helps 😄 Thank you for addressing the issue so fast!

Wauplin commented 1 day ago

Thanks @ademait! Seems like we can correctly retrieve runtime for all 4 Spaces now so all good :)