Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facing SSL Error with Huggingface pretrained models

I am facing below issue while loading the pretrained model from HuggingFace.

HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /roberta-base/resolve/main/config.json (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1125)')))

The line that is causing the issue is

tokenizer = AutoTokenizer.from_pretrained('roberta-base')

I never faced this issue before and it was working absolutely fine earlier. I am clueless.

like image 465
chaitu Avatar asked Sep 02 '25 15:09

chaitu


2 Answers

Adding the following to the top of the code worked for me:

import requests
from huggingface_hub import configure_http_backend

def backend_factory() -> requests.Session:
    session = requests.Session()
    session.verify = False
    return session

configure_http_backend(backend_factory=backend_factory)
like image 85
Sholto Armstrong Avatar answered Sep 05 '25 16:09

Sholto Armstrong


For Enterprise users, if your Enterprise has enterprise root certs, you may need to set this environment variable to know where your ca-certificates.crt bundle is. Testing via the requests module was not able to reproduce the error as those requests went out properly, but for the pull to work via Huggingface we had to set this variable first.

Hope this saves someone a few hours :)

export REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt
like image 25
dward4 Avatar answered Sep 05 '25 14:09

dward4