SSL fails and we can't pull from HuggingFaceHub
Author: Sleemanmunk
Pull request: no

### System Info

- `transformers` version: 4.31.0
- Platform: Linux-5.4.72-microsoft-standard-WSL2-x86_64-with-glibc2.35
- Python version: 3.10.12
- Huggingface_hub version: 0.16.4
- Safetensors version: 0.3.2
- Accelerate version: not installed
- Accelerate config: not found
- PyTorch version (GPU?): not installed (NA)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: No
- Using distributed or parallel set-up in script?: No

### Who can help?

SSL is failing with Huggingfacehub and we can't pull even a simple tokenizer. Yesterday with our full implementation this worked. This example is minimal with a fresh build to avoid confounding factors.

None of PyTorch, TensorFlow >= 2.0, or Flax have been found. Models won't be available and only tokenizers, configuration and file/data utilities can be used.
Traceback (most recent call last):
  File "/home/saleem/.local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 467, in _make_request
    self._validate_conn(conn)
  File "/home/saleem/.local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 1092, in _validate_conn
    conn.connect()
  File "/home/saleem/.local/lib/python3.10/site-packages/urllib3/connection.py", line 642, in connect
    sock_and_verified = _ssl_wrap_socket_and_match_hostname(
  File "/home/saleem/.local/lib/python3.10/site-packages/urllib3/connection.py", line 783, in _ssl_wrap_socket_and_match_hostname
    ssl_sock = ssl_wrap_socket(
  File "/home/saleem/.local/lib/python3.10/site-packages/urllib3/util/ssl_.py", line 469, in ssl_wrap_socket
    ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_in_tls, server_hostname)
  File "/home/saleem/.local/lib/python3.10/site-packages/urllib3/util/ssl_.py", line 513, in _ssl_wrap_socket_impl
    return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
  File "/usr/lib/python3.10/ssl.py", line 513, in wrap_socket
    return self.sslsocket_class._create(
  File "/usr/lib/python3.10/ssl.py", line 1071, in _create
    self.do_handshake()
  File "/usr/lib/python3.10/ssl.py", line 1342, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1007)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/saleem/.local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 790, in urlopen
    response = self._make_request(
  File "/home/saleem/.local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 491, in _make_request
    raise new_e
urllib3.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1007)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/saleem/.local/lib/python3.10/site-packages/requests/adapters.py", line 486, in send
    resp = conn.urlopen(
  File "/home/saleem/.local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 844, in urlopen
    retries = retries.increment(
  File "/home/saleem/.local/lib/python3.10/site-packages/urllib3/util/retry.py", line 515, in increment
    raise MaxRetryError(_pool, url, reason) from reason  # type: ignore[arg-type]
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /gpt2/resolve/main/tokenizer_config.json (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1007)')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/mnt/c/Users/saleem/Desktop/test.py", line 2, in <module>
    tokenizer = AutoTokenizer.from_pretrained('gpt2')
  File "/home/saleem/.local/lib/python3.10/site-packages/transformers/models/auto/tokenization_auto.py", line 652, in from_pretrained
    tokenizer_config = get_tokenizer_config(pretrained_model_name_or_path, **kwargs)
  File "/home/saleem/.local/lib/python3.10/site-packages/transformers/models/auto/tokenization_auto.py", line 496, in get_tokenizer_config
    resolved_config_file = cached_file(
  File "/home/saleem/.local/lib/python3.10/site-packages/transformers/utils/hub.py", line 417, in cached_file
    resolved_file = hf_hub_download(
  File "/home/saleem/.local/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py", line 118, in _inner_fn
    return fn(*args, **kwargs)
  File "/home/saleem/.local/lib/python3.10/site-packages/huggingface_hub/file_download.py", line 1195, in hf_hub_download
    metadata = get_hf_file_metadata(
  File "/home/saleem/.local/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py", line 118, in _inner_fn
    return fn(*args, **kwargs)
  File "/home/saleem/.local/lib/python3.10/site-packages/huggingface_hub/file_download.py", line 1532, in get_hf_file_metadata
    r = _request_wrapper(
  File "/home/saleem/.local/lib/python3.10/site-packages/huggingface_hub/file_download.py", line 407, in _request_wrapper
    response = _request_wrapper(
  File "/home/saleem/.local/lib/python3.10/site-packages/huggingface_hub/file_download.py", line 442, in _request_wrapper
    return http_backoff(
  File "/home/saleem/.local/lib/python3.10/site-packages/huggingface_hub/utils/_http.py", line 258, in http_backoff
    response = session.request(method=method, url=url, **kwargs)
  File "/home/saleem/.local/lib/python3.10/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/saleem/.local/lib/python3.10/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
  File "/home/saleem/.local/lib/python3.10/site-packages/huggingface_hub/utils/_http.py", line 63, in send
    return super().send(request, *args, **kwargs)
  File "/home/saleem/.local/lib/python3.10/site-packages/requests/adapters.py", line 517, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: (MaxRetryError("HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /gpt2/resolve/main/tokenizer_config.json (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1007)')))"), '(Request ID: a7ce5e76-2190-4579-b0e7-655993202fd7)')

### Information

- [X] The official example scripts
- [ ] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained('gpt2')

### Expected behavior

Tokenizer downloads successfully

Comments:
This is a duplicate of #17611, our hub was down for a bit yesterday, everything should be back up now. 

We had this problem all day. The solutions in #17611 do not work, and the problem persists today.

On my minimal build I was able to reproduce the SSL workaround by setting CURL_CA_BUNDLE and downgrading requests, 

but that only leads to this error:

  File "/mnt/c/Users/saleem/Desktop/test.py", line 2, in <module>
    tokenizer = AutoTokenizer.from_pretrained('gpt2')
  File "/home/saleem/.local/lib/python3.10/site-packages/transformers/models/auto/tokenization_auto.py", line 652, in from_pretrained
    tokenizer_config = get_tokenizer_config(pretrained_model_name_or_path, **kwargs)
  File "/home/saleem/.local/lib/python3.10/site-packages/transformers/models/auto/tokenization_auto.py", line 496, in get_tokenizer_config
    resolved_config_file = cached_file(
  File "/home/saleem/.local/lib/python3.10/site-packages/transformers/utils/hub.py", line 417, in cached_file
    resolved_file = hf_hub_download(
  File "/home/saleem/.local/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py", line 118, in _inner_fn
    return fn(*args, **kwargs)
  File "/home/saleem/.local/lib/python3.10/site-packages/huggingface_hub/file_download.py", line 1214, in hf_hub_download
    raise OSError("Distant resource does not seem to be on huggingface.co (missing commit header).")
OSError: Distant resource does not seem to be on huggingface.co (missing commit header).

Then I invite you to read [this tutorial](https://saturncloud.io/blog/facing-ssl-error-with-huggingface-pretrained-models-a-comprehensive-guide/#:~:text=SSL%20errors%20with%20Huggingface%20pretrained%20models%20can%20be%20frustrating%2C%20but,back%20to%20your%20NLP%20projects.). Hub is working alright on our ends

> This is a duplicate of #17611, our hub was down for a bit yesterday, everything should be back up now.

Yes, I also faced a similar issue, It is back to normal now. 

Closing this issue as the root problem [seemed to come from the firewall](https://github.com/huggingface/huggingface_hub/issues/1600#issuecomment-1684391061).

ME TOO ,TRIED TO CLOSE SSLVVERIFICATION;DIDN'T WORK