SSL error in accessing MNIST dataset

Completed

While trying to open the MNIST dataset...

from keras.datasets import mnist
(train_images, train_labels), (test_images, test_labels) = mnist.load_data()

I get an SSL error...

Exception: URL fetch failure on https://s3.amazonaws.com/img-datasets/mnist.npz: None -- [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)

I tried accessing the data from a browser and had no problem, so I don't think it's a system issue.  So, it seems to be an issue with PyCharm (perhaps related to pip in PyCharm library?). In googling, some have suggested I not use PyCharm to manage libraries (but use only command line).  Is this where I'm going wrong?  This would make it harder to use VirtualEnv.

How do I resolve this?

Thanks

Eric

1
5 comments
Avatar
Permanently deleted user

Okay, found the answer.  Let me post it here for others...

 Mac OSX python ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)

Browse to Applications/Python 3.6 folder and double-click Install Certificates.command

 

3
Avatar
Permanently deleted user

 Incase of linux...
go to .local/python3.X/lib/python3.6/site-packages/keras/utils/data_utils.py

 and below import statements add these----

```

import requests
requests.packages.urllib3.disable_warnings()
import ssl

try:
_create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
# Legacy Python that doesn't verify HTTPS certificates by default
pass
else:
# Handle target environment that doesn't support HTTPS verification
ssl._create_default_https_context = _create_unverified_https_context
```

 now try new instance of python and ..hopefully it works

 

 

1

thanks('CRLannister') 

0

I found the solution to the error, so you can also check out the following article in detail:- https://cheapsslweb.com/blog/ssl-certificate-verify-failed-error-in-python/.

I hope it helps!

 

0

Hi Eric,

The [SSL: CERTIFICATE_VERIFY_FAILED] error typically means your Python environment can't validate the SSL certificate when fetching the MNIST dataset. Since it works in your browser, the issue is likely with Python, not PyCharm directly.

Try updating the certifi package using pip install --upgrade certifi. On macOS, you can also run the Install Certificates.command script in the Python folder. If you’re using a PyCharm-managed virtual environment, try running the script outside PyCharm to isolate the issue. Avoid disabling SSL verification. As a workaround, you can manually download the dataset and load it locally.

0

Please sign in to leave a comment.