8

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.

chaitu
  • 1,036
  • 5
  • 20
  • 39
  • 3
    Try adding `os.environ["CURL_CA_BUNDLE"]=""` as the first line in your script. – Kris Mar 31 '22 at 12:24
  • Yes it worked. Thanks. How was it made possible @Kris – chaitu Mar 31 '22 at 13:44
  • huggingface.co now has a bad SSL certificate, your lib internally tries to verify it and fails. By adding the env variable, you basically disabled the SSL verification. But, this is actually not a good thing. Probably a work around only. All communications will be unverified in your app because of this. – Kris Apr 01 '22 at 04:32

4 Answers4

4

You can import a self-signed certificate on Windows machine.

To add a certificate to the Trusted Root Certification Authorities store on Windows, you can follow these steps:

  1. Download the root certificate from the website, procedure to download the certificates using chrome browser are as follows:

    • Open the website (https://huggingface.co/)

    • In the URL tab you can see small lock icon, click on it

    • Click on "Connection is secure"

    • Click on "Certificate is valid"

    • CLick on "Details" tab

    • From certificate hierarchy select root certificate in our case it is "caadmin.netskope.com"

    • Click on "Export..." and save it in your system

      Refer this image to select and export root certificate

  2. Add downloaded certificate to "Trusted Root Certification Authorities" using following steps:

    • Open the Command Prompt as an administrator.

    • Type the following command to add the certificate to the Trusted Root Certification Authorities store

      certutil -addstore "Root" <path/to/certificate>
      

      You will receive a message indicating that the certificate was added to the store.

To verify if certificate is added to root or not, follow these steps :

  1. Press the windows button and type "mmc" and press enter, this will open the Microsoft management console.
  2. On the File menu, click Add/Remove Snap-in.
  3. In the Available snap-ins box, click Certificates, and then click Add.
  4. Click Computer account, and then click next.
  5. Click Local computer, and then click Finish.
  6. Click OK to close the Add or Remove Snap-ins dialog box.
  7. In the console tree, click Certificates (Local Computer), and then click the Trusted Root Certification Authorities folder.
  8. Verify that the certificate is in the Trusted Root Certification Authorities folder.

NOTE : It's recommended to consult with your IT administrator or security team to ensure that your system is configured correctly.

Please let me know if there's anything else I could help you with.

cronoik
  • 15,434
  • 3
  • 40
  • 78
  • Installed certutil based on https://learnings.bolmaster2.com/posts/add-certificates-to-trust-stores.html, but `certutil -addstore "Root" /Users/username/Downloads/huggingface.co.cer` yields `Usage: certutil -d ` – John Jiang Feb 20 '23 at 18:04
4

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'] = ''
TheTechRobo the Nerd
  • 1,249
  • 15
  • 28
1

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.

aaronsnoswell
  • 6,051
  • 5
  • 47
  • 69
0

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
dward4
  • 1,615
  • 3
  • 15
  • 30