Connection Error - Please help

I keep getting this error while loading the dataset:

Downloading and preparing dataset 786.68 MiB (download: 786.68 MiB, generated: Unknown size, total: 786.68 MiB) to /root/tensorflow_datasets/cats_vs_dogs/4.0.0...
Dl Completed...: 0%
0/1 [00:00<?, ? url/s]
Dl Size...:
0/0 [00:00<?, ? MiB/s]
---------------------------------------------------------------------------
ConnectionResetError                      Traceback (most recent call last)
File /usr/lib/python3/dist-packages/urllib3/connectionpool.py:665, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
    664 # Make the request on the httplib connection object.
--> 665 httplib_response = self._make_request(
    666     conn,
    667     method,
    668     url,
    669     timeout=timeout_obj,
    670     body=body,
    671     headers=headers,
    672     chunked=chunked,
    673 )
    675 # If we're going to release the connection in ``finally:``, then
    676 # the response doesn't need to know about the connection. Otherwise
    677 # it will also try to release it and we'll have a double-release
    678 # mess.

File /usr/lib/python3/dist-packages/urllib3/connectionpool.py:376, in HTTPConnectionPool._make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
    375 try:
--> 376     self._validate_conn(conn)
    377 except (SocketTimeout, BaseSSLError) as e:
    378     # Py2 raises this as a BaseSSLError, Py3 raises it as socket timeout.

File /usr/lib/python3/dist-packages/urllib3/connectionpool.py:996, in HTTPSConnectionPool._validate_conn(self, conn)
    995 if not getattr(conn, "sock", None):  # AppEngine might not have  `.sock`
--> 996     conn.connect()
    998 if not conn.is_verified:

File /usr/lib/python3/dist-packages/urllib3/connection.py:366, in VerifiedHTTPSConnection.connect(self)
    364     context.load_default_certs()
--> 366 self.sock = ssl_wrap_socket(
    367     sock=conn,
    368     keyfile=self.key_file,
    369     certfile=self.cert_file,
    370     key_password=self.key_password,
    371     ca_certs=self.ca_certs,
    372     ca_cert_dir=self.ca_cert_dir,
    373     server_hostname=server_hostname,
    374     ssl_context=context,
    375 )
    377 if self.assert_fingerprint:

File /usr/lib/python3/dist-packages/urllib3/util/ssl_.py:370, in ssl_wrap_socket(sock, keyfile, certfile, cert_reqs, ca_certs, server_hostname, ssl_version, ciphers, ssl_context, ca_cert_dir, key_password)
    369 if HAS_SNI and server_hostname is not None:
--> 370     return context.wrap_socket(sock, server_hostname=server_hostname)
    372 warnings.warn(
    373     "An HTTPS request has been made, but the SNI (Server Name "
    374     "Indication) extension to TLS is not available on this platform. "
   (...)
    380     SNIMissingWarning,
    381 )

File /usr/lib/python3.8/ssl.py:500, in SSLContext.wrap_socket(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, session)
    494 def wrap_socket(self, sock, server_side=False,
    495                 do_handshake_on_connect=True,
    496                 suppress_ragged_eofs=True,
    497                 server_hostname=None, session=None):
    498     # SSLSocket class handles server_hostname encoding before it calls
    499     # ctx._wrap_socket()
--> 500     return self.sslsocket_class._create(
    501         sock=sock,
    502         server_side=server_side,
    503         do_handshake_on_connect=do_handshake_on_connect,
    504         suppress_ragged_eofs=suppress_ragged_eofs,
    505         server_hostname=server_hostname,
    506         context=self,
    507         session=session
    508     )

File /usr/lib/python3.8/ssl.py:1040, in SSLSocket._create(cls, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, context, session)
   1039             raise ValueError("do_handshake_on_connect should not be specified for non-blocking sockets")
-> 1040         self.do_handshake()
   1041 except (OSError, ValueError):

File /usr/lib/python3.8/ssl.py:1309, in SSLSocket.do_handshake(self, block)
   1308         self.settimeout(None)
-> 1309     self._sslobj.do_handshake()
   1310 finally:

ConnectionResetError: [Errno 104] Connection reset by peer

During handling of the above exception, another exception occurred:

ProtocolError                             Traceback (most recent call last)
File /usr/lib/python3/dist-packages/requests/adapters.py:439, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies)
    438 if not chunked:
--> 439     resp = conn.urlopen(
    440         method=request.method,
    441         url=url,
    442         body=request.body,
    443         headers=request.headers,
    444         redirect=False,
    445         assert_same_host=False,
    446         preload_content=False,
    447         decode_content=False,
    448         retries=self.max_retries,
    449         timeout=timeout
    450     )
    452 # Send the request.
    453 else:

File /usr/lib/python3/dist-packages/urllib3/connectionpool.py:719, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
    717     e = ProtocolError("Connection aborted.", e)
--> 719 retries = retries.increment(
    720     method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
    721 )
    722 retries.sleep()

File /usr/lib/python3/dist-packages/urllib3/util/retry.py:400, in Retry.increment(self, method, url, response, error, _pool, _stacktrace)
    399 if read is False or not self._is_method_retryable(method):
--> 400     raise six.reraise(type(error), error, _stacktrace)
    401 elif read is not None:

File /usr/lib/python3/dist-packages/six.py:702, in reraise(tp, value, tb)
    701 if value.__traceback__ is not tb:
--> 702     raise value.with_traceback(tb)
    703 raise value

File /usr/lib/python3/dist-packages/urllib3/connectionpool.py:665, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
    664 # Make the request on the httplib connection object.
--> 665 httplib_response = self._make_request(
    666     conn,
    667     method,
    668     url,
    669     timeout=timeout_obj,
    670     body=body,
    671     headers=headers,
    672     chunked=chunked,
    673 )
    675 # If we're going to release the connection in ``finally:``, then
    676 # the response doesn't need to know about the connection. Otherwise
    677 # it will also try to release it and we'll have a double-release
    678 # mess.

File /usr/lib/python3/dist-packages/urllib3/connectionpool.py:376, in HTTPConnectionPool._make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
    375 try:
--> 376     self._validate_conn(conn)
    377 except (SocketTimeout, BaseSSLError) as e:
    378     # Py2 raises this as a BaseSSLError, Py3 raises it as socket timeout.

File /usr/lib/python3/dist-packages/urllib3/connectionpool.py:996, in HTTPSConnectionPool._validate_conn(self, conn)
    995 if not getattr(conn, "sock", None):  # AppEngine might not have  `.sock`
--> 996     conn.connect()
    998 if not conn.is_verified:

File /usr/lib/python3/dist-packages/urllib3/connection.py:366, in VerifiedHTTPSConnection.connect(self)
    364     context.load_default_certs()
--> 366 self.sock = ssl_wrap_socket(
    367     sock=conn,
    368     keyfile=self.key_file,
    369     certfile=self.cert_file,
    370     key_password=self.key_password,
    371     ca_certs=self.ca_certs,
    372     ca_cert_dir=self.ca_cert_dir,
    373     server_hostname=server_hostname,
    374     ssl_context=context,
    375 )
    377 if self.assert_fingerprint:

File /usr/lib/python3/dist-packages/urllib3/util/ssl_.py:370, in ssl_wrap_socket(sock, keyfile, certfile, cert_reqs, ca_certs, server_hostname, ssl_version, ciphers, ssl_context, ca_cert_dir, key_password)
    369 if HAS_SNI and server_hostname is not None:
--> 370     return context.wrap_socket(sock, server_hostname=server_hostname)
    372 warnings.warn(
    373     "An HTTPS request has been made, but the SNI (Server Name "
    374     "Indication) extension to TLS is not available on this platform. "
   (...)
    380     SNIMissingWarning,
    381 )

File /usr/lib/python3.8/ssl.py:500, in SSLContext.wrap_socket(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, session)
    494 def wrap_socket(self, sock, server_side=False,
    495                 do_handshake_on_connect=True,
    496                 suppress_ragged_eofs=True,
    497                 server_hostname=None, session=None):
    498     # SSLSocket class handles server_hostname encoding before it calls
    499     # ctx._wrap_socket()
--> 500     return self.sslsocket_class._create(
    501         sock=sock,
    502         server_side=server_side,
    503         do_handshake_on_connect=do_handshake_on_connect,
    504         suppress_ragged_eofs=suppress_ragged_eofs,
    505         server_hostname=server_hostname,
    506         context=self,
    507         session=session
    508     )

File /usr/lib/python3.8/ssl.py:1040, in SSLSocket._create(cls, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, context, session)
   1039             raise ValueError("do_handshake_on_connect should not be specified for non-blocking sockets")
-> 1040         self.do_handshake()
   1041 except (OSError, ValueError):

File /usr/lib/python3.8/ssl.py:1309, in SSLSocket.do_handshake(self, block)
   1308         self.settimeout(None)
-> 1309     self._sslobj.do_handshake()
   1310 finally:

ProtocolError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))

During handling of the above exception, another exception occurred:

ConnectionError                           Traceback (most recent call last)
Input In [11], in <cell line: 11>()
      3 splits = ['train[:10%]', 'train[-10%:-5%]', 'train[-5%:]']
      5 # Remember to use `cats_vs_dogs:4.*.*` 
      6 # https://www.tensorflow.org/datasets/catalog/cats_vs_dogs
      7     
      8 # It has been downloaded for you so use the data_dir parameter 
      9 # else it will try to download the dataset and give you an error here
---> 11 splits, info = tfds.load('cats_vs_dogs:4.*.*', split=splits)
     13 (train_examples, validation_examples, test_examples) = splits
     15 # Testing lengths of the data if they are loaded correctly. Do not edit the code below

File /usr/local/lib/python3.8/dist-packages/tensorflow_datasets/core/logging/__init__.py:250, in load.<locals>.decorator(function, unused_none_instance, args, kwargs)
    248 name = args[0] if args else kwargs["name"]
    249 try:
--> 250   return function(*args, **kwargs)
    251 except Exception:
    252   metadata.mark_error()

File /usr/local/lib/python3.8/dist-packages/tensorflow_datasets/core/load.py:575, in load(name, split, data_dir, batch_size, shuffle_files, download, as_supervised, decoders, read_config, with_info, builder_kwargs, download_and_prepare_kwargs, as_dataset_kwargs, try_gcs)
    573 if download:
    574   download_and_prepare_kwargs = download_and_prepare_kwargs or {}
--> 575   dbuilder.download_and_prepare(**download_and_prepare_kwargs)
    577 if as_dataset_kwargs is None:
    578   as_dataset_kwargs = {}

File /usr/local/lib/python3.8/dist-packages/tensorflow_datasets/core/dataset_builder.py:523, in DatasetBuilder.download_and_prepare(self, download_dir, download_config, file_format)
    521   self.info.read_from_directory(self._data_dir)
    522 else:
--> 523   self._download_and_prepare(
    524       dl_manager=dl_manager,
    525       download_config=download_config,
    526   )
    528   # NOTE: If modifying the lines below to put additional information in
    529   # DatasetInfo, you'll likely also want to update
    530   # DatasetInfo.read_from_directory to possibly restore these attributes
    531   # when reading from package data.
    532   self.info.download_size = dl_manager.downloaded_size

File /usr/local/lib/python3.8/dist-packages/tensorflow_datasets/core/dataset_builder.py:1244, in GeneratorBasedBuilder._download_and_prepare(self, dl_manager, download_config)
   1242 else:
   1243   optional_pipeline_kwargs = {}
-> 1244 split_generators = self._split_generators(  # pylint: disable=unexpected-keyword-arg
   1245     dl_manager, **optional_pipeline_kwargs)
   1246 # TODO(tfds): Could be removed once all datasets are migrated.
   1247 # https://github.com/tensorflow/datasets/issues/2537
   1248 # Legacy mode (eventually convert list[SplitGeneratorLegacy] -> dict)
   1249 split_generators = split_builder.normalize_legacy_split_generators(
   1250     split_generators=split_generators,
   1251     generator_fn=self._generate_examples,
   1252     is_beam=isinstance(self, BeamBasedBuilder),
   1253 )

File /usr/local/lib/python3.8/dist-packages/tensorflow_datasets/image_classification/cats_vs_dogs.py:70, in CatsVsDogs._split_generators(self, dl_manager)
     69 def _split_generators(self, dl_manager):
---> 70   path = dl_manager.download(_URL)
     72   # There is no predefined train/val/test split for this dataset.
     73   return [
     74       tfds.core.SplitGenerator(
     75           name=tfds.Split.TRAIN,
   (...)
     78           }),
     79   ]

File /usr/local/lib/python3.8/dist-packages/tensorflow_datasets/core/download/download_manager.py:552, in DownloadManager.download(self, url_or_urls)
    550 # Add progress bar to follow the download state
    551 with self._downloader.tqdm():
--> 552   return _map_promise(self._download, url_or_urls)

File /usr/local/lib/python3.8/dist-packages/tensorflow_datasets/core/download/download_manager.py:770, in _map_promise(map_fn, all_inputs)
    768 """Map the function into each element and resolve the promise."""
    769 all_promises = tf.nest.map_structure(map_fn, all_inputs)  # Apply the function
--> 770 res = tf.nest.map_structure(lambda p: p.get(), all_promises)  # Wait promises
    771 return res

File /usr/local/lib/python3.8/dist-packages/tensorflow/python/util/nest.py:916, in map_structure(func, *structure, **kwargs)
    912 flat_structure = (flatten(s, expand_composites) for s in structure)
    913 entries = zip(*flat_structure)
    915 return pack_sequence_as(
--> 916     structure[0], [func(*x) for x in entries],
    917     expand_composites=expand_composites)

File /usr/local/lib/python3.8/dist-packages/tensorflow/python/util/nest.py:916, in <listcomp>(.0)
    912 flat_structure = (flatten(s, expand_composites) for s in structure)
    913 entries = zip(*flat_structure)
    915 return pack_sequence_as(
--> 916     structure[0], [func(*x) for x in entries],
    917     expand_composites=expand_composites)

File /usr/local/lib/python3.8/dist-packages/tensorflow_datasets/core/download/download_manager.py:770, in _map_promise.<locals>.<lambda>(p)
    768 """Map the function into each element and resolve the promise."""
    769 all_promises = tf.nest.map_structure(map_fn, all_inputs)  # Apply the function
--> 770 res = tf.nest.map_structure(lambda p: p.get(), all_promises)  # Wait promises
    771 return res

File /usr/local/lib/python3.8/dist-packages/promise/promise.py:512, in Promise.get(self, timeout)
    510 target = self._target()
    511 self._wait(timeout or DEFAULT_TIMEOUT)
--> 512 return self._target_settled_value(_raise=True)

File /usr/local/lib/python3.8/dist-packages/promise/promise.py:516, in Promise._target_settled_value(self, _raise)
    514 def _target_settled_value(self, _raise=False):
    515     # type: (bool) -> Any
--> 516     return self._target()._settled_value(_raise)

File /usr/local/lib/python3.8/dist-packages/promise/promise.py:226, in Promise._settled_value(self, _raise)
    224 if _raise:
    225     raise_val = self._fulfillment_handler0
--> 226     reraise(type(raise_val), raise_val, self._traceback)
    227 return self._fulfillment_handler0

File /usr/lib/python3/dist-packages/six.py:703, in reraise(tp, value, tb)
    701     if value.__traceback__ is not tb:
    702         raise value.with_traceback(tb)
--> 703     raise value
    704 finally:
    705     value = None

File /usr/local/lib/python3.8/dist-packages/promise/promise.py:844, in _process_future_result.<locals>.handle_future_result(future)
    841 def handle_future_result(future):
    842     # type: (Any) -> None
    843     try:
--> 844         resolve(future.result())
    845     except Exception as e:
    846         tb = exc_info()[2]

File /usr/lib/python3.8/concurrent/futures/_base.py:437, in Future.result(self, timeout)
    435     raise CancelledError()
    436 elif self._state == FINISHED:
--> 437     return self.__get_result()
    439 self._condition.wait(timeout)
    441 if self._state in [CANCELLED, CANCELLED_AND_NOTIFIED]:

File /usr/lib/python3.8/concurrent/futures/_base.py:389, in Future.__get_result(self)
    387 if self._exception:
    388     try:
--> 389         raise self._exception
    390     finally:
    391         # Break a reference cycle with the exception in self._exception
    392         self = None

File /usr/lib/python3.8/concurrent/futures/thread.py:57, in _WorkItem.run(self)
     54     return
     56 try:
---> 57     result = self.fn(*self.args, **self.kwargs)
     58 except BaseException as exc:
     59     self.future.set_exception(exc)

File /usr/local/lib/python3.8/dist-packages/tensorflow_datasets/core/download/downloader.py:217, in _Downloader._sync_download(self, url, destination_path, verify)
    214 except tf.errors.UnimplementedError:
    215   pass
--> 217 with _open_url(url, verify=verify) as (response, iter_content):
    218   fname = _get_filename(response)
    219   path = os.path.join(destination_path, fname)

File /usr/lib/python3.8/contextlib.py:113, in _GeneratorContextManager.__enter__(self)
    111 del self.args, self.kwds, self.func
    112 try:
--> 113     return next(self.gen)
    114 except StopIteration:
    115     raise RuntimeError("generator didn't yield") from None

File /usr/local/lib/python3.8/dist-packages/tensorflow_datasets/core/download/downloader.py:278, in _open_with_requests(url, **kwargs)
    276 if _DRIVE_URL.match(url):
    277   url = _normalize_drive_url(url)
--> 278 with session.get(url, stream=True, **kwargs) as response:
    279   _assert_status(response)
    280   yield (response, response.iter_content(chunk_size=io.DEFAULT_BUFFER_SIZE))

File /usr/lib/python3/dist-packages/requests/sessions.py:546, in Session.get(self, url, **kwargs)
    538 r"""Sends a GET request. Returns :class:`Response` object.
    539 
    540 :param url: URL for the new :class:`Request` object.
    541 :param \*\*kwargs: Optional arguments that ``request`` takes.
    542 :rtype: requests.Response
    543 """
    545 kwargs.setdefault('allow_redirects', True)
--> 546 return self.request('GET', url, **kwargs)

File /usr/lib/python3/dist-packages/requests/sessions.py:533, in Session.request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
    528 send_kwargs = {
    529     'timeout': timeout,
    530     'allow_redirects': allow_redirects,
    531 }
    532 send_kwargs.update(settings)
--> 533 resp = self.send(prep, **send_kwargs)
    535 return resp

File /usr/lib/python3/dist-packages/requests/sessions.py:646, in Session.send(self, request, **kwargs)
    643 start = preferred_clock()
    645 # Send the request
--> 646 r = adapter.send(request, **kwargs)
    648 # Total elapsed time of the request (approximately)
    649 elapsed = preferred_clock() - start

File /usr/lib/python3/dist-packages/requests/adapters.py:498, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies)
    495             raise
    497 except (ProtocolError, socket.error) as err:
--> 498     raise ConnectionError(err, request=request)
    500 except MaxRetryError as e:
    501     if isinstance(e.reason, ConnectTimeoutError):
    502         # TODO: Remove this in 3.0.0: see #2811

ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))

I found similar errors posted from other courses, but couldn’t find any in this course.
Please help me get this fixed at the earliest, my subscription is ending soon.

Hi, @Lakshmi_Narayana :wave:

This looks like a network issue. Are you running this code in a hosted or local environment?

Hi Yurij,
I’m running this from within coursera, and everything else on my pc seems to be working without complaining about the internet.

When I tried to just submit without running, I got a different error message from the same block:

Cell #3. Can't compile the student's code. Error: TypeError("__init__() missing 2 required positional arguments: 'op' and 'message'",)