'Error [SSL: CERTIFICATE_VERIFY_FAILED] - (_ssl.c:1056) when loading datasets from Keras, macOS Catalina

When I tried to download datasets from Keras in R on my Mac (MacOS Catalina), I have this error:

> mnist <- dataset_mnist() #Downloading MNIST from Keras

Error in py_call_impl(callable, dots$args, dots$keywords) : 
  Exception: URL fetch failure on https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz: None -- [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)

Detailed traceback: 
  File "/Users/jinduong/.virtualenvs/r-reticulate/lib/python3.7/site-packages/tensorflow/python/keras/datasets/mnist.py", line 49, in load_data
    file_hash='8a61469f7ea1b51cbae51d4f78837e45')
  File "/Users/jinduong/.virtualenvs/r-reticulate/lib/python3.7/site-packages/tensorflow/python/keras/utils/data_utils.py", line 250, in get_file
    raise Exception(error_msg.format(origin, e.errno, e.reason))

So I have an error of [SSL: CERTIFICATE_VERIFY_FAILED] with (_ssl.c:1056)

I did try almost, if not all of everything I can find in Google, including (not chronological order):

1. Change Python default to 3.8 (the latest one) from Python 2.7

2. Try to update Certificate by manually running the file "Install Certificates.command" and "Update Shell Profile.command".

3. Try $ pip install --upgrade certifi

DEPRECATION: Python 2.7 reached the end of its lifeon January 1st, 2020. Please upgrade your Python asPython 2.7 is no longer maintained. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Defaulting to user installation because normal site-packages is not writeable
Requirement already up-to-date: certifi in ./Library/Python/2.7/lib/python/site-packages (2019.11.28)

4. Try bash /Applications/Python*/Install\ Certificates.command

 -- pip install --upgrade certifi
Requirement already up-to-date: certifi in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (2019.11.28)
WARNING: You are using pip version 19.2.3, however version 20.0.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
 -- removing any existing file or link
 -- creating symlink to certifi certificate bundle
 -- setting permissions
 -- update complete

5. Install request in terminal

6. Clear Chrome cache

And unfortunately, none of them work for me. Strangely, it works just fine on my other Macbook Air with me basically doing nothing. Also, I have very little experience with Unix so I have no clue what I should do.

(PS: I'm using the latest Rstudio-1.2.5033, R version 3.6.2, and my Tensorflow is 1.13.1 as the later version could not work on R with Keras for me)



Solution 1:[1]

you need to install certificates via .command files.

go to this path and run the .command file :

/Applications/Python\ 3.X/Install\ Certificates.command

Solution 2:[2]

I used this code:

    function writeMeta() {
        //alert('ok');
        $("meta[name='viewport']").attr('content', 'width=device-width, initial-scale=0.4'); 
        //$("#page").html(''); 
    }
    window.onload = writeMeta;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 l.mome
Solution 2 Giangoul