Error running second codes cell of C1W3 Lab 1

Hi experts,

When running the C1W3 Lab 1, 2nd codes cell:

mnist = tf.keras.datasets.mnist

(x_train, y_train),(x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0

caused errors:

Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz

---------------------------------------------------------------------------
OSError                                   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)
    727         try:
--> 728             raise err
    729         finally:

/opt/conda/lib/python3.7/socket.py in create_connection(address, timeout, source_address)
    715                 sock.bind(source_address)
--> 716             sock.connect(sa)
    717             # Break explicitly a reference cycle

OSError: [Errno 99] Cannot assign requested address

During handling of the above exception, another exception occurred:

URLError                                  Traceback (most recent call last)
/opt/conda/lib/python3.7/site-packages/tensorflow_core/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)
    263       try:
--> 264         urlretrieve(origin, fpath, dl_progress)
    265       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 99] Cannot assign requested address>

During handling of the above exception, another exception occurred:

Exception                                 Traceback (most recent call last)
<ipython-input-6-95eb1c3cd4db> in <module>
      1 mnist = tf.keras.datasets.mnist
      2 
----> 3 (x_train, y_train),(x_test, y_test) = mnist.load_data()
      4 x_train, x_test = x_train / 255.0, x_test / 255.0

/opt/conda/lib/python3.7/site-packages/tensorflow_core/python/keras/datasets/mnist.py in load_data(path)
     48       origin=origin_folder + 'mnist.npz',
     49       file_hash=
---> 50       '731c5ac602752760c8e48fbffcf8c3b850d9dc2a2aedcf2cc48468fc17b673d1')
     51   with np.load(path, allow_pickle=True) as f:
     52     x_train, y_train = f['x_train'], f['y_train']

/opt/conda/lib/python3.7/site-packages/tensorflow_core/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)
    266         raise Exception(error_msg.format(origin, e.code, e.msg))
    267       except URLError as e:
--> 268         raise Exception(error_msg.format(origin, e.errno, e.reason))
    269     except (Exception, KeyboardInterrupt) as e:
    270       if os.path.exists(fpath):

Exception: URL fetch failure on https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz: None -- [Errno 99] Cannot assign requested address

Have tried re-opened the notebook but same error when executing same codes cell.

Any idea what needs fixing?

Thanks,
MCW

Hi @Mun_Chung_Wong

The link for the dataset is correct, but if the dataset cannot be fetched, it my be a potential issue with the network or environment where the code is being executed.

Try running the provided code snippet locally, if this runs without any errors, then the cloud notebook session might have some network issues that need to be reported.

Hope it helps!

Ok thanks I will try running locally then.

[UPDATE]
Works locally … now the C1W3 assignment runs into same issue.

Tested the assignment locally and happy with the result, should I just go
ahead and submit it? Will the grading process throws error and fail me for
the underlying issue?

Thanks,
MCW

1 Like

hi @chris.favila

I think there is an issue ongoing with this, so notifying you, if this need to updated or corrected.

i suppose the same issue was noticed DLS course.

Regards
DP

Lucky the assignment grading isn’t affected although exhibiting same errors.

Thanks,
MCW

2 Likes

Hi everyone. Thank you for reporting. We’ve followed up with Coursera re: this issue. Will place a workaround for now while it’s being fixed. Will update this thread as soon as it’s ready. Thanks!

Hi! The labs are now updated and shouldn’t require an external download of the MNIST dataset. You can relaunch from the classroom to see the changes. Thank you!

1 Like

A similar problem seems to be occurring.
The problem now though is that the hostname ‘storage.googleapis.com’ cannot be resolved. I verified that ‘googleapis.com’ can be resolved, but the ‘storage.googleapis.com’ cannot (see below)

import subprocess

cmds = [
    "getent hosts storage.googleapis.com",
    "getent hosts googleapis.com"
]

for cmd in cmds:
    result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
    print(f"for cmd:'{cmd}'\n\treturncode:({result.returncode})\n\tstdout:'{result.stdout}'\n\tstderr:'{result.stderr}''")

truncated output:

for cmd:'getent hosts storage.googleapis.com'
	returncode:(2)
	stdout:''
	stderr:'''
for cmd:'getent hosts googleapis.com'
	returncode:(0)
	stdout:'142.251.16.104  googleapis.com

I can resolve both locally though, so it must be a DNS issue on the host running the code.
The previous issue seemed to have had a resolution that de-necessitated fetching the dataset. Maybe the version rolled back? Is there a way to specify the version in collab maybe? Is there an easy way to cache the data manually?

Here is a copy of the error output that I get on collab, running the code as-is:

---------------------------------------------------------------------------
gaierror                                  Traceback (most recent call last)
File /usr/lib/python3.11/urllib/request.py:1348, in AbstractHTTPHandler.do_open(self, http_class, req, **http_conn_args)
   1347 try:
-> 1348     h.request(req.get_method(), req.selector, req.data, headers,
   1349               encode_chunked=req.has_header('Transfer-encoding'))
   1350 except OSError as err: # timeout error

File /usr/lib/python3.11/http/client.py:1282, in HTTPConnection.request(self, method, url, body, headers, encode_chunked)
   1281 """Send a complete request to the server."""
-> 1282 self._send_request(method, url, body, headers, encode_chunked)

File /usr/lib/python3.11/http/client.py:1328, in HTTPConnection._send_request(self, method, url, body, headers, encode_chunked)
   1327     body = _encode(body, 'body')
-> 1328 self.endheaders(body, encode_chunked=encode_chunked)

File /usr/lib/python3.11/http/client.py:1277, in HTTPConnection.endheaders(self, message_body, encode_chunked)
   1276     raise CannotSendHeader()
-> 1277 self._send_output(message_body, encode_chunked=encode_chunked)

File /usr/lib/python3.11/http/client.py:1037, in HTTPConnection._send_output(self, message_body, encode_chunked)
   1036 del self._buffer[:]
-> 1037 self.send(msg)
   1039 if message_body is not None:
   1040 
   1041     # create a consistent interface to message_body

File /usr/lib/python3.11/http/client.py:975, in HTTPConnection.send(self, data)
    974 if self.auto_open:
--> 975     self.connect()
    976 else:

File /usr/lib/python3.11/http/client.py:1447, in HTTPSConnection.connect(self)
   1445 "Connect to a host on a given (SSL) port."
-> 1447 super().connect()
   1449 if self._tunnel_host:

File /usr/lib/python3.11/http/client.py:941, in HTTPConnection.connect(self)
    940 sys.audit("http.client.connect", self, self.host, self.port)
--> 941 self.sock = self._create_connection(
    942     (self.host,self.port), self.timeout, self.source_address)
    943 # Might fail in OSs that don't implement TCP_NODELAY

File /usr/lib/python3.11/socket.py:826, in create_connection(address, timeout, source_address, all_errors)
    825 exceptions = []
--> 826 for res in getaddrinfo(host, port, 0, SOCK_STREAM):
    827     af, socktype, proto, canonname, sa = res

File /usr/lib/python3.11/socket.py:961, in getaddrinfo(host, port, family, type, proto, flags)
    960 addrlist = []
--> 961 for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
    962     af, socktype, proto, canonname, sa = res

gaierror: [Errno -5] No address associated with hostname

During handling of the above exception, another exception occurred:

URLError                                  Traceback (most recent call last)
File /usr/local/lib/python3.11/dist-packages/keras/src/utils/file_utils.py:291, in get_file(fname, origin, untar, md5_hash, file_hash, cache_subdir, hash_algorithm, extract, archive_format, cache_dir, force_download)
    290 try:
--> 291     urlretrieve(origin, fpath, DLProgbar())
    292 except urllib.error.HTTPError as e:

File /usr/lib/python3.11/urllib/request.py:241, in urlretrieve(url, filename, reporthook, data)
    239 url_type, path = _splittype(url)
--> 241 with contextlib.closing(urlopen(url, data)) as fp:
    242     headers = fp.info()

File /usr/lib/python3.11/urllib/request.py:216, in urlopen(url, data, timeout, cafile, capath, cadefault, context)
    215     opener = _opener
--> 216 return opener.open(url, data, timeout)

File /usr/lib/python3.11/urllib/request.py:519, in OpenerDirector.open(self, fullurl, data, timeout)
    518 sys.audit('urllib.Request', req.full_url, req.data, req.headers, req.get_method())
--> 519 response = self._open(req, data)
    521 # post-process response

File /usr/lib/python3.11/urllib/request.py:536, in OpenerDirector._open(self, req, data)
    535 protocol = req.type
--> 536 result = self._call_chain(self.handle_open, protocol, protocol +
    537                           '_open', req)
    538 if result:

File /usr/lib/python3.11/urllib/request.py:496, in OpenerDirector._call_chain(self, chain, kind, meth_name, *args)
    495 func = getattr(handler, meth_name)
--> 496 result = func(*args)
    497 if result is not None:

File /usr/lib/python3.11/urllib/request.py:1391, in HTTPSHandler.https_open(self, req)
   1390 def https_open(self, req):
-> 1391     return self.do_open(http.client.HTTPSConnection, req,
   1392         context=self._context, check_hostname=self._check_hostname)

File /usr/lib/python3.11/urllib/request.py:1351, in AbstractHTTPHandler.do_open(self, http_class, req, **http_conn_args)
   1350 except OSError as err: # timeout error
-> 1351     raise URLError(err)
   1352 r = h.getresponse()

URLError: <urlopen error [Errno -5] No address associated with hostname>

During handling of the above exception, another exception occurred:

Exception                                 Traceback (most recent call last)
Cell In[2], line 7
      5 # Load the Fashion MNIST dataset
      6 fmnist = tf.keras.datasets.fashion_mnist
----> 7 (training_images, training_labels), (test_images, test_labels) = fmnist.load_data()
      9 # Normalize the pixel values
     10 training_images = training_images / 255.0

File /usr/local/lib/python3.11/dist-packages/keras/src/datasets/fashion_mnist.py:78, in load_data()
     76 paths = []
     77 for fname in files:
---> 78     paths.append(get_file(fname, origin=base + fname, cache_subdir=dirname))
     80 with gzip.open(paths[0], "rb") as lbpath:
     81     y_train = np.frombuffer(lbpath.read(), np.uint8, offset=8)

File /usr/local/lib/python3.11/dist-packages/keras/src/utils/file_utils.py:295, in get_file(fname, origin, untar, md5_hash, file_hash, cache_subdir, hash_algorithm, extract, archive_format, cache_dir, force_download)
    293         raise Exception(error_msg.format(origin, e.code, e.msg))
    294     except urllib.error.URLError as e:
--> 295         raise Exception(error_msg.format(origin, e.errno, e.reason))
    296 except (Exception, KeyboardInterrupt):
    297     if os.path.exists(fpath):

Exception: URL fetch failure on XXXXXXXXstorage.googleapis.com/tensorflow/tf-keras-datasets/train-labels-idx1-ubyte.gz: None -- [Errno -5] No address associated with hostname

The 'X’s in the last part are only because the forum won’t accept my with urls

actually when I did the course I didn’t encounter the issue when my Google Collab was connected with my Google drive.

I remember although when Collab was not connected to drive, few of the assignments created problem.

but this issue seem more version related discrepancy.

Let me notify Chris.

Hi Brendan, and welcome to the Forum! Thank you for reporting this. Looks like a platform bug. We’ll look into it and update the notebook as necessary. Will update here asap. Thanks again!

Hi Brendan. Can you post the Coursera link to the exact lab you’re working on? It seems to be different from the one on this thread. C1W3 Lab 1 is working fine on my end. Thanks.

It looks like it’s working from here now too!
If you didn’t do anything to fix it, then I’m guessing it was stale DNS that auto-refreshed.
Or maybe there was an migration to IPv6 because DNS is returning IPv6 IP addresses now for both hostnames

Thanks for your assistance either way!

for cmd:'getent hosts storage.googleapis.com'
	returncode:(0)
	stdout:'2607:f8b0:4004:c1b::cf storage.googleapis.com'
...
for cmd:'getent hosts googleapis.com'
	returncode:(0)
	stdout:'2607:f8b0:4004:c06::93 googleapis.com'

I spoke too soon. It’s broken again now in the same way; and the googleapis.com is once again getting an IPv4 address.

for cmd:'getent hosts storage.googleapis.com'
	returncode:(2)
	stdout:''
	stderr:'''
for cmd:'getent hosts googleapis.com'
	returncode:(0)
	stdout:'172.253.115.106 googleapis.com
...

Got it. I was able to reproduce the issue. Will look into this and update asap. Thanks!

Hi. This should now be resolved and it’s working on my end. Please check. Thanks!

Sorry, I thought I had already replied, but yes, it was working as of your reply.
Thanks for the assistance!

1 Like