C4 W2 A2 [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)

This codebox:

IMG_SHAPE = IMG_SIZE + (3,)
base_model = tf.keras.applications.MobileNetV2(input_shape=IMG_SHAPE,
                                               include_top=True,
                                               weights='imagenet')

results with the following error:

Downloading data from https://storage.googleapis.com/tensorflow/keras-applications/mobilenet_v2/mobilenet_v2_weights_tf_dim_ordering_tf_kernels_1.0_160.h5
---------------------------------------------------------------------------
SSLCertVerificationError                  Traceback (most recent call last)
/opt/conda/lib/python3.7/urllib/request.py in do_open(self, http_class, req, **http_conn_args)
   1318                 h.request(req.get_method(), req.selector, req.data, headers,
-> 1319                           encode_chunked=req.has_header('Transfer-encoding'))
   1320             except OSError as err: # timeout error

/opt/conda/lib/python3.7/http/client.py in request(self, method, url, body, headers, encode_chunked)
   1251         """Send a complete request to the server."""
-> 1252         self._send_request(method, url, body, headers, encode_chunked)
   1253 

/opt/conda/lib/python3.7/http/client.py in _send_request(self, method, url, body, headers, encode_chunked)
   1297             body = _encode(body, 'body')
-> 1298         self.endheaders(body, encode_chunked=encode_chunked)
   1299 

/opt/conda/lib/python3.7/http/client.py in endheaders(self, message_body, encode_chunked)
   1246             raise CannotSendHeader()
-> 1247         self._send_output(message_body, encode_chunked=encode_chunked)
   1248 

/opt/conda/lib/python3.7/http/client.py in _send_output(self, message_body, encode_chunked)
   1025         del self._buffer[:]
-> 1026         self.send(msg)
   1027 

/opt/conda/lib/python3.7/http/client.py in send(self, data)
    965             if self.auto_open:
--> 966                 self.connect()
    967             else:

/opt/conda/lib/python3.7/http/client.py in connect(self)
   1421             self.sock = self._context.wrap_socket(self.sock,
-> 1422                                                   server_hostname=server_hostname)
   1423 

/opt/conda/lib/python3.7/ssl.py in wrap_socket(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, session)
    422             context=self,
--> 423             session=session
    424         )

/opt/conda/lib/python3.7/ssl.py in _create(cls, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, context, session)
    869                         raise ValueError("do_handshake_on_connect should not be specified for non-blocking sockets")
--> 870                     self.do_handshake()
    871             except (OSError, ValueError):

/opt/conda/lib/python3.7/ssl.py in do_handshake(self, block)
   1138                 self.settimeout(None)
-> 1139             self._sslobj.do_handshake()
   1140         finally:

SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)

During handling of the above exception, another exception occurred:

URLError                                  Traceback (most recent call last)
/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/utils/data_utils.py in get_file(fname, origin, untar, md5_hash, file_hash, cache_subdir, hash_algorithm, extract, archive_format, cache_dir)
    277       try:
--> 278         urlretrieve(origin, fpath, dl_progress)
    279       except HTTPError as e:

/opt/conda/lib/python3.7/urllib/request.py in urlretrieve(url, filename, reporthook, data)
    246 
--> 247     with contextlib.closing(urlopen(url, data)) as fp:
    248         headers = fp.info()

/opt/conda/lib/python3.7/urllib/request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
    221         opener = _opener
--> 222     return opener.open(url, data, timeout)
    223 

/opt/conda/lib/python3.7/urllib/request.py in open(self, fullurl, data, timeout)
    524 
--> 525         response = self._open(req, data)
    526 

/opt/conda/lib/python3.7/urllib/request.py in _open(self, req, data)
    542         result = self._call_chain(self.handle_open, protocol, protocol +
--> 543                                   '_open', req)
    544         if result:

/opt/conda/lib/python3.7/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args)
    502             func = getattr(handler, meth_name)
--> 503             result = func(*args)
    504             if result is not None:

/opt/conda/lib/python3.7/urllib/request.py in https_open(self, req)
   1361             return self.do_open(http.client.HTTPSConnection, req,
-> 1362                 context=self._context, check_hostname=self._check_hostname)
   1363 

/opt/conda/lib/python3.7/urllib/request.py in do_open(self, http_class, req, **http_conn_args)
   1320             except OSError as err: # timeout error
-> 1321                 raise URLError(err)
   1322             r = h.getresponse()

URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)>

During handling of the above exception, another exception occurred:

Exception                                 Traceback (most recent call last)
<ipython-input-41-370c4e2d1bf6> in <module>
      2 base_model = tf.keras.applications.MobileNetV2(input_shape=IMG_SHAPE,
      3                                                include_top=True,
----> 4                                                weights='imagenet')

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/applications/mobilenet_v2.py in MobileNetV2(input_shape, alpha, include_top, weights, input_tensor, pooling, classes, classifier_activation, **kwargs)
    401       weight_path = BASE_WEIGHT_PATH + model_name
    402       weights_path = data_utils.get_file(
--> 403           model_name, weight_path, cache_subdir='models')
    404     else:
    405       model_name = ('mobilenet_v2_weights_tf_dim_ordering_tf_kernels_' +

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/utils/data_utils.py in get_file(fname, origin, untar, md5_hash, file_hash, cache_subdir, hash_algorithm, extract, archive_format, cache_dir)
    280         raise Exception(error_msg.format(origin, e.code, e.msg))
    281       except URLError as e:
--> 282         raise Exception(error_msg.format(origin, e.errno, e.reason))
    283     except (Exception, KeyboardInterrupt) as e:
    284       if os.path.exists(fpath):

Exception: URL fetch failure on https://storage.googleapis.com/tensorflow/keras-applications/mobilenet_v2/mobilenet_v2_weights_tf_dim_ordering_tf_kernels_1.0_160.h5: None -- [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)

From what I understand googling, it may be either caused by the server hosting the jupyter notebook, or the server hosting TonsorFlow API…
Could anyone take a look at this? I would appreciate help! Thanks in advance!

Are you running this thru Coursera Labs, or are you running it locally or via another service?

I just ran that cell on the Labs environment, and had no errors.

Running through Coursera Labs, this is the URL:

https://www.coursera.org/learn/convolutional-neural-networks/programming/nZima/transfer-learning-with-mobilenet/lab?path=%2Fnotebooks%2FW2A2%2FTransfer_learning_with_MobileNet_v1.ipynb

It seems to work OK for me.
Are you still having an issue?

Started working now :slight_smile:

Got something similar by the looks of it

Downloading data from https://storage.googleapis.com/tensorflow/keras-applications/mobilenet_v2/mobilenet_v2_weights_tf_dim_ordering_tf_kernels_1.0_160.h5
---------------------------------------------------------------------------
gaierror                                  Traceback (most recent call last)
/opt/conda/lib/python3.7/urllib/request.py in do_open(self, http_class, req, **http_conn_args)
   1318                 h.request(req.get_method(), req.selector, req.data, headers,
-> 1319                           encode_chunked=req.has_header('Transfer-encoding'))
   1320             except OSError as err: # timeout error

/opt/conda/lib/python3.7/http/client.py in request(self, method, url, body, headers, encode_chunked)
   1251         """Send a complete request to the server."""
-> 1252         self._send_request(method, url, body, headers, encode_chunked)
   1253 

/opt/conda/lib/python3.7/http/client.py in _send_request(self, method, url, body, headers, encode_chunked)
   1297             body = _encode(body, 'body')
-> 1298         self.endheaders(body, encode_chunked=encode_chunked)
   1299 

/opt/conda/lib/python3.7/http/client.py in endheaders(self, message_body, encode_chunked)
   1246             raise CannotSendHeader()
-> 1247         self._send_output(message_body, encode_chunked=encode_chunked)
   1248 

/opt/conda/lib/python3.7/http/client.py in _send_output(self, message_body, encode_chunked)
   1025         del self._buffer[:]
-> 1026         self.send(msg)
   1027 

/opt/conda/lib/python3.7/http/client.py in send(self, data)
    965             if self.auto_open:
--> 966                 self.connect()
    967             else:

/opt/conda/lib/python3.7/http/client.py in connect(self)
   1413 
-> 1414             super().connect()
   1415 

/opt/conda/lib/python3.7/http/client.py in connect(self)
    937         self.sock = self._create_connection(
--> 938             (self.host,self.port), self.timeout, self.source_address)
    939         self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)

/opt/conda/lib/python3.7/socket.py in create_connection(address, timeout, source_address)
    706     err = None
--> 707     for res in getaddrinfo(host, port, 0, SOCK_STREAM):
    708         af, socktype, proto, canonname, sa = res

/opt/conda/lib/python3.7/socket.py in getaddrinfo(host, port, family, type, proto, flags)
    751     addrlist = []
--> 752     for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
    753         af, socktype, proto, canonname, sa = res

gaierror: [Errno -3] Temporary failure in name resolution

During handling of the above exception, another exception occurred:

URLError                                  Traceback (most recent call last)
/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/utils/data_utils.py in get_file(fname, origin, untar, md5_hash, file_hash, cache_subdir, hash_algorithm, extract, archive_format, cache_dir)
    277       try:
--> 278         urlretrieve(origin, fpath, dl_progress)
    279       except HTTPError as e:

/opt/conda/lib/python3.7/urllib/request.py in urlretrieve(url, filename, reporthook, data)
    246 
--> 247     with contextlib.closing(urlopen(url, data)) as fp:
    248         headers = fp.info()

/opt/conda/lib/python3.7/urllib/request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
    221         opener = _opener
--> 222     return opener.open(url, data, timeout)
    223 

/opt/conda/lib/python3.7/urllib/request.py in open(self, fullurl, data, timeout)
    524 
--> 525         response = self._open(req, data)
    526 

/opt/conda/lib/python3.7/urllib/request.py in _open(self, req, data)
    542         result = self._call_chain(self.handle_open, protocol, protocol +
--> 543                                   '_open', req)
    544         if result:

/opt/conda/lib/python3.7/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args)
    502             func = getattr(handler, meth_name)
--> 503             result = func(*args)
    504             if result is not None:

/opt/conda/lib/python3.7/urllib/request.py in https_open(self, req)
   1361             return self.do_open(http.client.HTTPSConnection, req,
-> 1362                 context=self._context, check_hostname=self._check_hostname)
   1363 

/opt/conda/lib/python3.7/urllib/request.py in do_open(self, http_class, req, **http_conn_args)
   1320             except OSError as err: # timeout error
-> 1321                 raise URLError(err)
   1322             r = h.getresponse()

URLError: <urlopen error [Errno -3] Temporary failure in name resolution>

During handling of the above exception, another exception occurred:

Exception                                 Traceback (most recent call last)
<ipython-input-41-370c4e2d1bf6> in <module>
      2 base_model = tf.keras.applications.MobileNetV2(input_shape=IMG_SHAPE,
      3                                                include_top=True,
----> 4                                                weights='imagenet')

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/applications/mobilenet_v2.py in MobileNetV2(input_shape, alpha, include_top, weights, input_tensor, pooling, classes, classifier_activation, **kwargs)
    401       weight_path = BASE_WEIGHT_PATH + model_name
    402       weights_path = data_utils.get_file(
--> 403           model_name, weight_path, cache_subdir='models')
    404     else:
    405       model_name = ('mobilenet_v2_weights_tf_dim_ordering_tf_kernels_' +

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/utils/data_utils.py in get_file(fname, origin, untar, md5_hash, file_hash, cache_subdir, hash_algorithm, extract, archive_format, cache_dir)
    280         raise Exception(error_msg.format(origin, e.code, e.msg))
    281       except URLError as e:
--> 282         raise Exception(error_msg.format(origin, e.errno, e.reason))
    283     except (Exception, KeyboardInterrupt) as e:
    284       if os.path.exists(fpath):

Exception: URL fetch failure on https://storage.googleapis.com/tensorflow/keras-applications/mobilenet_v2/mobilenet_v2_weights_tf_dim_ordering_tf_kernels_1.0_160.h5: None -- [Errno -3] Temporary failure in name resolution

Well, it’s not quite the same error, although it occurs on a similar URL. The previous error was an error verifying the SSL certificate. You’re getting a temporary name resolution error, which is a DNS problem of some sort. We’ve been seeing transient DNS errors from various notebooks across DLS recently. For most people, it just goes away if you try again over a few hours. E.g. here’s a recent thread about this type of error.

Thank you for your answer, Paul. That is a bit frustrating since the deadline for submission was tonight. Will try again tomorrow morning.

Don’t worry! The deadlines here are all fake in the sense that there is no penalty for missing them. They just automatically reset and they start hassling you about the next one. But it really doesn’t matter. Given that, you might well ask why they bother, but they’ve been studying their students like lab rats and running experiments on us. They apparently have stats that show that hassling people in this way increases their chances of successfully completing courses. Now the next level of experimentation is whether my revealing this secret to you will harm your chances of completion! I certainly hope not. :laughing:

But actually the fact that the deadlines are optional is not a secret: it is documented under “Course Info” on the left menu on any of the course pages.

Thank you, Paul. Submitting a day after the deadline did not lead to any issue, indeed. Will still feign to be unaware the deadlines do not matter but if I do not complete the specialization I will certainly put the blame on you for disclosing that not-so-secret piece of information :upside_down_face: