tfds.load() gives ConnectionResetError

I am running tensorflow 2.0.0 (python 3.7.4) on a conda virtual environment on Mac. I am trying to get the IMDb dataset through the following code:

```
import tensorflow_datasets as tfds

tfds.load('imdb_reviews/subwords8k', split=(tfds.Split.TRAIN, tfds.Split.TEST), with_info = True, as_supervised = True)
```

to which I am getting the following error:

> ConnectionError: ('Connection aborted.', ConnectionResetError(54, 'Connection reset by peer'))


I have asked github tensorflow support (here: https://github.com/tensorflow/tensorflow/issues/36561) and they have concluded that the issue is raised by getresponse() method and it's not a TF issue.

They showed a similar stackoverflow error which involved Requests library. It was solved by installing security packages. I have installed security packages for Requests, Tensorflow and Tensorflow-Datasets using these commands:

> conda install -c anaconda pyasn1 ndg-httpsclient pyopenssl 
> conda install -c anaconda "requests[security]" 
> conda install -c anaconda "tensorflow[security]" 
> conda install -c anaconda "tensorflow-datasets[security]"

But the issue is persistent. The stacktrace is:

> File "/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/urllib3/connectionpool.py", line 672, in urlopen chunked=chunked,
> 
> File "/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/urllib3/connectionpool.py", line 421, in _make_request six.raise_from(e, None)
> 
> File "", line 3, in raise_from
> 
> File "/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/urllib3/connectionpool.py", line 416, in _make_request httplib_response = conn.getresponse()
> 
> File "/Users/User/anaconda3/envs/tf/lib/python3.7/http/client.py", line 1344, in getresponse response.begin()
> 
> File "/Users/User/anaconda3/envs/tf/lib/python3.7/http/client.py", line 306, in begin version, status, reason = self._read_status()
> 
> File "/Users/User/anaconda3/envs/tf/lib/python3.7/http/client.py", line 267, in _read_status line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
> 
> File "/Users/User/anaconda3/envs/tf/lib/python3.7/socket.py", line 589, in readinto return self._sock.recv_into(b)
> 
> ConnectionResetError: [Errno 54] Connection reset by peer
> 
> During handling of the above exception, another exception occurred:
> 
> Traceback (most recent call last):
> 
> File "/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/requests/adapters.py", line 449, in send timeout=timeout
> 
> File "/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/urllib3/connectionpool.py", line 720, in urlopen method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
> 
> File "/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/urllib3/util/retry.py", line 400, in increment raise six.reraise(type(error), error, _stacktrace)
> 
> File "/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/urllib3/packages/six.py", line 734, in reraise raise value.with_traceback(tb)
> 
> File "/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/urllib3/connectionpool.py", line 672, in urlopen chunked=chunked,
> 
> File "/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/urllib3/connectionpool.py", line 421, in _make_request six.raise_from(e, None)
> 
> File "", line 3, in raise_from
> 
> File "/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/urllib3/connectionpool.py", line 416, in _make_request httplib_response = conn.getresponse()
> 
> File "/Users/User/anaconda3/envs/tf/lib/python3.7/http/client.py", line 1344, in getresponse response.begin()
> 
> File "/Users/User/anaconda3/envs/tf/lib/python3.7/http/client.py", line 306, in begin version, status, reason = self._read_status()
> 
> File "/Users/User/anaconda3/envs/tf/lib/python3.7/http/client.py", line 267, in _read_status line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
> 
> File "/Users/User/anaconda3/envs/tf/lib/python3.7/socket.py", line 589, in readinto return self._sock.recv_into(b)
> 
> ProtocolError: ('Connection aborted.', ConnectionResetError(54, 'Connection reset by peer'))
> 
> During handling of the above exception, another exception occurred:
> 
> Traceback (most recent call last):
> 
> File "/Users/User/nlp1.py", line 13, in (train_data, test_data), info = tfds.load('imdb_reviews/subwords8k', split=(tfds.Split.TRAIN, tfds.Split.TEST), with_info = True, as_supervised = True)
> 
> File "/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow_datasets/core/api_utils.py", line 52, in disallow_positional_args_dec return fn(*args, **kwargs)
> 
> File "/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow_datasets/core/registered.py", line 300, in load dbuilder.download_and_prepare(**download_and_prepare_kwargs)
> 
> File "/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow_datasets/core/api_utils.py", line 52, in disallow_positional_args_dec return fn(*args, **kwargs)
> 
> File "/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow_datasets/core/dataset_builder.py", line 287, in download_and_prepare download_config=download_config)
> 
> File "/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow_datasets/core/dataset_builder.py", line 948, in _download_and_prepare max_examples_per_split=download_config.max_examples_per_split,
> 
> File "/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow_datasets/core/dataset_builder.py", line 804, in _download_and_prepare for split_generator in self._split_generators(dl_manager):
> 
> File "/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow_datasets/text/imdb.py", line 129, in _split_generators arch_path = dl_manager.download(_DOWNLOAD_URL)
> 
> File "/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow_datasets/core/download/download_manager.py", line 301, in download return _map_promise(self._download, url_or_urls)
> 
> File "/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow_datasets/core/download/download_manager.py", line 395, in _map_promise res = utils.map_nested(_wait_on_promise, all_promises)
> 
> File "/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow_datasets/core/utils/py_utils.py", line 143, in map_nested return function(data_struct)
> 
> File "/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow_datasets/core/download/download_manager.py", line 379, in _wait_on_promise return p.get()
> 
> File "/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/promise/promise.py", line 510, in get return self._target_settled_value(_raise=True)
> 
> File "/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/promise/promise.py", line 514, in _target_settled_value return self._target()._settled_value(_raise)
> 
> File "/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/promise/promise.py", line 224, in _settled_value reraise(type(raise_val), raise_val, self._traceback)
> 
> File "/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/six.py", line 703, in reraise raise value
> 
> File "/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/promise/promise.py", line 842, in handle_future_result resolve(future.result())
> 
> File "/Users/User/anaconda3/envs/tf/lib/python3.7/concurrent/futures/_base.py", line 428, in result return self.__get_result()
> 
> File "/Users/User/anaconda3/envs/tf/lib/python3.7/concurrent/futures/_base.py", line 384, in __get_result raise self._exception
> 
> File "/Users/User/anaconda3/envs/tf/lib/python3.7/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, **self.kwargs)
> 
> File "/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow_datasets/core/download/downloader.py", line 231, in _sync_download response = session.get(url, stream=True)
> 
> File "/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/requests/sessions.py", line 546, in get return self.request('GET', url, **kwargs)
> 
> File "/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/requests/sessions.py", line 533, in request resp = self.send(prep, **send_kwargs)
> 
> File "/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/requests/sessions.py", line 646, in send r = adapter.send(request, **kwargs)
> 
> File "/Users/User/anaconda3/envs/tf/lib/python3.7/site-packages/requests/adapters.py", line 498, in send raise ConnectionError(err, request=request)
> 
> ConnectionError: ('Connection aborted.', ConnectionResetError(54, 'Connection reset by peer'))

I am unable to find any support with this issue anywhere.

Hi @anas0001,

The exception you’re receiving is due to the remote server you’re connecting to resetting the connection. Requests has no control over that and there isn’t enough info here to determine what’s happening.

That said, this isn’t a defect in Requests which is the purpose for this issue tracker. I’d recommend creating an issue on StackOverflow if you haven’t already and perhaps trying your script on another network to see if it persists.

thank you