Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

Commit

Permalink
Fix ConnectionError in download_mnist (pytorch#61789)
Browse files Browse the repository at this point in the history
Summary:
Fixes issues like the following error. Note that `ConnectionResetError` is a subclass of `ConnectionError`.

```
+ python tools/download_mnist.py --quiet -d test/cpp/api/mnist
Downloading http://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz ...
Traceback (most recent call last):
  File "tools/download_mnist.py", line 93, in <module>
    main()
  File "tools/download_mnist.py", line 86, in main
    download(path, resource, options.quiet)
  File "tools/download_mnist.py", line 42, in download
    urlretrieve(url, destination_path, reporthook=hook)
  File "/opt/conda/lib/python3.6/urllib/request.py", line 277, in urlretrieve
    block = fp.read(bs)
  File "/opt/conda/lib/python3.6/http/client.py", line 463, in read
    n = self.readinto(b)
  File "/opt/conda/lib/python3.6/http/client.py", line 507, in readinto
    n = self.fp.readinto(b)
  File "/opt/conda/lib/python3.6/socket.py", line 586, in readinto
    return self._sock.recv_into(b)
ConnectionResetError: [Errno 104] Connection reset by peer
```

Pull Request resolved: pytorch#61789

Reviewed By: dreiss

Differential Revision: D29745459

Pulled By: zhouzhuojie

fbshipit-source-id: 2deb668bd74478f32bd01704d4362e8a4d95087b
  • Loading branch information
zhouzhuojie authored and facebook-github-bot committed Jul 17, 2021
1 parent 4e2fe97 commit cb6841b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion tools/download_mnist.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def download(destination_path: str, resource: str, quiet: bool) -> None:
try:
hook = None if quiet else report_download_progress
urlretrieve(url, destination_path, reporthook=hook)
except URLError as e:
except (URLError, ConnectionError) as e:
print('Failed to download (trying next):\n{}'.format(e))
continue
finally:
Expand Down

0 comments on commit cb6841b

Please sign in to comment.