Reputation: 1216
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.
Upvotes: 26
Views: 66787
Reputation: 283
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)
Upvotes: 15
Reputation: 51
Try installing the certificate package:
pip install python-certifi-win32
Upvotes: 2
Reputation: 31
Go to this file in your environment Lib\site-packages\requests\sessions.py
Do this - update the code like below in the merge_environment_settings function
verify = False #merge_setting(verify, self.verify)
after download modify it back
verify = merge_setting(verify, self.verify)
Upvotes: 2
Reputation: 1
This is what worked for me. source: pip install fails with "connection error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:598)"
its a problem with pip and its servers. Open your pip.ini file. Mine was at c:\users\SPaZ\AppData\local\pip\pip.ini and add the following & save it:
[global]
trusted-host = pypi.python.org
pypi.org
files.pythonhosted.org
raw.githubusercontent.com
github.com
Upvotes: 0
Reputation: 1942
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
Upvotes: 15
Reputation: 6261
The CURL_CA_BUNDLE
fix did not work for me. Instead, I was able to add the following lines to the start of my script;
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
And the error does not occur now.
This answer was from https://github.com/pytorch/pytorch/issues/33288#issuecomment-954160699.
Upvotes: 4
Reputation: 161
Downgrading requests to 2.27.1 and adding the following code snippet to the beginning of your program file should fix the problem.
'''This following code will set the CURL_CA_BUNDLE environment variable to an empty string in the Python os module'''
import os
os.environ['CURL_CA_BUNDLE'] = ''
Upvotes: 16