Reputation: 1429
I am facing below issue while loading the pretrained BERT model from HuggingFace due to SSL certificate error.
SSLError: HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /dslim/bert-base-NER/resolve/main/tokenizer_config.json (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1108)')))
tokenizer = AutoTokenizer.from_pretrained("dslim/bert-base-NER")
from transformers import AutoTokenizer, AutoModelForTokenClassification
from transformers import AutoModelForCausalLM, AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("dslim/bert-base-NER")
model = AutoModelForTokenClassification.from_pretrained("dslim/bert-base-NER")
I am expecting to download pre-trained models while running the code in jupyter lab on Windows.
Upvotes: 17
Views: 71164
Reputation: 175
Please check if you have the access token to download the hugging face model.
Please refer the video https://www.youtube.com/watch?v=t-0s_2uZZU0 and check the information given between timestamps 1:44:18 - 1:45:34
Upvotes: 0
Reputation: 721
import os
os.environ['CURL_CA_BUNDLE'] = r"C:/examples/ssls/all.crt"
os.environ['REQUESTS_CA_BUNDLE'] = r"C:/examples/ssls/all.crt"
Note this error may come for other connections also.
Download all those certificates from browser address browser padlock.
Download the "chain" not just individual (it appeared 2nd option in combo while save). The question of this post has error related to chain. Because verification will happen till root CA. Probably it was downloaded as single cert. (refer screenshot)
Multiple .crt files if you have concat all using concat command (comes with git bash)
concat a.crt b.crt c.crt > all.crt.
Upvotes: 1
Reputation: 640
Here's a solution that worked for me:
import os os.environ['CURL_CA_BUNDLE'] = 'C:/Users/xxxx/Downloads/certificates/huggingface.co.crt' from transformers import AutoTokenizer tokenizer = AutoTokenizer.from_pretrained('BAAI/bge-reranker-v2-m3')
Upvotes: 1
Reputation: 31
By setting the below environment variables it worked:
import os
os.environ['CURL_CA_BUNDLE'] = ''
os.environ['REQUESTS_CA_BUNDLE'] = ''
Upvotes: 1
Reputation: 61
Here is a solution if you want the actual certificate:
If you are on linux you can use this bash script I made to download the certificate file from Cisco Umberella, convert it to .crt and update the certificates folder. Script:
#!/bin/sh
curl -O https://d36u8deuxga9bo.cloudfront.net/certificates/Cisco_Umbrella_Root_CA.cer
openssl x509 -inform PEM -in Cisco_Umbrella_Root_CA.cer -out cisco.crt
rm -rf Cisco_Umbrella_Root_CA.cer
sudo mv cisco.crt /usr/local/share/ca-certificates/
sudo update-ca-certificates
After adding the new certificate from Cisco you still need to set the environment variable CURL_CA_BUNDLE
before using the from_pretrained
function. This is because the certifi package used by transformers for ca-certification defaults to some .pem file inside the certifi package. We instead set it to the directory your downloaded certificate was just moved to by update-ca-certificates
. Here is how:
import os
from transformers import AutoModel, AutoTokenizer
os.environ["CURL_CA_BUNDLE"] = "/etc/ssl/certs/ca-certificates.crt"
model = AutoModel.from_pretrained("intfloat/multilingual-e5-small")
tokenizer = AutoTokenizer.from_pretrained("intfloat/multilingual-e5-small")
Now it should download the model without any security warnings. Hope this helped.
Upvotes: 6
Reputation: 83
I was working with my linux machine ,Looking at server of hugging face found that they were working fine ,it was just the issue of proxy directly export proxy in .zshrc work for me.
export https_proxy=http://127.0.0.1:7890
export http_proxy=http://127.0.0.1:7890
export all_proxy=socks5://127.0.0.1:7890
using source ~/.zshrc I tried downgrading request library but didn't worked ,by managing the proxy it did work for me .
Upvotes: 0
Reputation: 1
A working solution for this is Enable your device for development.
if you're writing software with Visual Studio on a computer for the first time, you will need to enable Developer Mode on both the development PC and on any devices you'll use to test your code.
Upvotes: 0
Reputation: 15033
A working solution to this is the following:
1)
pip install requests==2.27.1
Please note that both prerequisites need to take place, just running the following code will not work unless you have that specific version of requests (I had to downgrade in my case from 2.29.0
to 2.27.1
.
2)
import os
os.environ['CURL_CA_BUNDLE'] = ''
Upvotes: 24
Reputation: 171
Try to add the following in your main python file
import os
os.environ['CURL_CA_BUNDLE'] = ''
Upvotes: 11