huggingface / huggingface_hub

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

MaxRetryError with login in huggingface_hub[cli] #2312

Open enori opened 4 months ago

enori commented 4 months ago

Describe the bug

I have repeatedly encountered the following error and have been struggling with it.

requests.exceptions.SSLError: (MaxRetryError("HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /api/whoami-v2 (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)')))"), '(Request ID: aa881b7a-68ba-4c48-ba16-c90f3468a90d)')

I understand that it can be resolved using the following methods:

  1. Downgrade the version of requests
    $ pip install requests==2.27.1
  2. Disable certificate verification (This is not recommended from a security perspective...)

    import os
    
    os.environ['CURL_CA_BUNDLE'] = ''
    os.environ['REQUESTS_CA_BUNDLE'] = ''

I would like to fix this bug or have it documented in the official documentation.

I'm a beginner with Hugging Face, so my abilities are limited, but I will try to make pull requests if possible. Thank you.

Reproduction

from huggingface_hub import login
login()

Logs

requests.exceptions.SSLError: (MaxRetryError("HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /api/whoami-v2 (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)')))"), '(Request ID: aa881b7a-68ba-4c48-ba16-c90f3468a90d)')

System info

- huggingface_hub version: 0.23.2
- Platform: Linux-5.14.0-284.55.1.el9_2.x86_64-x86_64-with-glibc2.34
- Python version: 3.9.18
- Running in iPython ?: No
- Running in notebook ?: No
- Running in Google Colab ?: No
- Token path ?: /opt/app-root/src/.cache/huggingface/token
- Has saved token ?: True
- Configured git credential helpers: 
- FastAI: N/A
- Tensorflow: N/A
- Torch: 2.0.1+cu118
- Jinja2: 3.1.3
- Graphviz: N/A
- keras: N/A
- Pydot: N/A
- Pillow: 10.2.0
- hf_transfer: N/A
- gradio: N/A
- tensorboard: 2.6.2.2
- numpy: 1.24.4
- pydantic: 1.10.14
- aiohttp: 3.9.3
- ENDPOINT: https://huggingface.co
- HF_HUB_CACHE: /opt/app-root/src/.cache/huggingface/hub
- HF_ASSETS_CACHE: /opt/app-root/src/.cache/huggingface/assets
- HF_TOKEN_PATH: /opt/app-root/src/.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 4 months ago

Hi @enori, sorry you are facing this issue. This is probably not an issue with huggingface_hub but a network or configuration issue on your side. Can it be that you are working behind a proxy? Or that your firewall is blocking some requests?

Can you try to run these snippets to confirm it's a problem with the network and not something inside huggingface_hub?

  1. 
    import requests

requests.get("https://huggingface.co/api/tasks").raise_for_status()


2.
```py
from huggingface_hub.utils import get_session

get_session().get("https://huggingface.co/api/tasks").raise_for_status()

3.

import requests
from huggingface_hub.utils import build_hf_headers

headers = build_hf_headers(token="...")  # your token here, only for the test
response = requests.get("https://huggingface.co/api/whoami-v2")
response.raise_for_status()
print(response.json())

Let me know what happens when you run these. I expect all of them to fail with the same error.