URL Fetch Failure Downloading Fashion MNIST

I’m sure I’m making an extreme beginner mistake here, but the following code (based on the basic image classification tutorial on the tensorflow website) is failing to download the MNIST Fashion dataset.

import matplotlib.pyplot as plt
print(tf.__version__)  # 2.14.0 :)

fashion_mnist = tf.keras.datasets.fashion_mnist

(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()

I’ve been stuck for two days and haven’t found anything that works online. Pls help :frowning:

Here’s the full error message:

Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 1348, in do_open h.request(req.get_method(), req.selector, req.data, headers, File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/http/client.py", line 1282, in request self._send_request(method, url, body, headers, encode_chunked) File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/http/client.py", line 1328, in _send_request self.endheaders(body, encode_chunked=encode_chunked) File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/http/client.py", line 1277, in endheaders self._send_output(message_body, encode_chunked=encode_chunked) File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/http/client.py", line 1037, in _send_output self.send(msg) File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/http/client.py", line 975, in send self.connect() File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/http/client.py", line 1454, in connect self.sock = self._context.wrap_socket(self.sock, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ssl.py", line 517, in wrap_socket return self.sslsocket_class._create( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ssl.py", line 1075, in _create self.do_handshake() File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ssl.py", line 1346, in do_handshake self._sslobj.do_handshake() ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:992)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/Users/barryyu/Documents/GitHub/tensorflow-audio-recognition/venv/lib/python3.11/site-packages/keras/src/utils/data_utils.py”, line 347, in get_file
urlretrieve(origin, fpath, DLProgbar())
File “/Users/barryyu/Documents/GitHub/tensorflow-audio-recognition/venv/lib/python3.11/site-packages/keras/src/utils/data_utils.py”, line 85, in urlretrieve
response = urlopen(url, data)
^^^^^^^^^^^^^^^^^^
File “/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py”, line 216, in urlopen
return opener.open(url, data, timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py”, line 519, in open
response = self._open(req, data)
^^^^^^^^^^^^^^^^^^^^^
File “/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py”, line 536, in _open
result = self._call_chain(self.handle_open, protocol, protocol +
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py”, line 496, in _call_chain
result = func(*args)
^^^^^^^^^^^
File “/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py”, line 1391, in https_open
return self.do_open(http.client.HTTPSConnection, req,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py”, line 1351, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:992)>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/Users/barryyu/Documents/GitHub/tensorflow-audio-recognition/main.py”, line 9, in
(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()
^^^^^^^^^^^^^^^^^^^^^^^^^
File “/Users/barryyu/Documents/GitHub/tensorflow-audio-recognition/venv/lib/python3.11/site-packages/keras/src/datasets/fashion_mnist.py”, line 93, in load_data
paths.append(get_file(fname, origin=base + fname, cache_subdir=dirname))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/Users/barryyu/Documents/GitHub/tensorflow-audio-recognition/venv/lib/python3.11/site-packages/keras/src/utils/data_utils.py”, line 351, in get_file
raise Exception(error_msg.format(origin, e.errno, e.reason))
Exception: URL fetch failure on https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-labels-idx1-ubyte.gz: None – [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:992)

For some additional context I’m using a Macbook with Pycharm. Thank you so much.

Hi @Barry_Yu
Did you try out to go to Applications >> python[version] >> Install Certificates.command ?
Thank you.

1 Like

It worked! Thank you!

1 Like