[英]How to fix "ConnectionResetError: [Errno 104] Connection reset by peer" error?
I'm trying to download MNIST dataset on GPU of google colaboratory.我正在尝试在 google colaboratory 的 GPU 上下载 MNIST 数据集。 But it is showing me "ConnectionResetError: [Errno 104] Connection reset by peer" error message.
但它向我显示“ConnectionResetError:[Errno 104] Connection reset by peer”错误消息。
from sklearn.datasets import fetch_mldata
dataset = fetch_mldata('MNIST original')
data = dataset.data
And the following error I'm getting:我得到以下错误:
/usr/local/lib/python3.6/dist-packages/sklearn/utils/deprecation.py:85: DeprecationWarning: Function fetch_mldata is deprecated; fetch_mldata was deprecated in version 0.20 and will be removed in version 0.22. Please use fetch_openml.
warnings.warn(msg, category=DeprecationWarning)
/usr/local/lib/python3.6/dist-packages/sklearn/utils/deprecation.py:85: DeprecationWarning: Function mldata_filename is deprecated; mldata_filename was deprecated in version 0.20 and will be removed in version 0.22. Please use fetch_openml.
warnings.warn(msg, category=DeprecationWarning)
---------------------------------------------------------------------------
ConnectionResetError Traceback (most recent call last)
<ipython-input-8-8ae517e9a088> in <module>()
1 from sklearn.datasets import fetch_mldata
----> 2 dataset = fetch_mldata('MNIST original')
3 data = dataset.data
11 frames
/usr/lib/python3.6/socket.py in readinto(self, b)
584 while True:
585 try:
--> 586 return self._sock.recv_into(b)
587 except timeout:
588 self._timeout_occurred = True
ConnectionResetError: [Errno 104] Connection reset by peer
It is taking too long to show this error message.显示此错误消息的时间过长。 How to resolve this?
如何解决这个问题?
Take a look at this response, it is very similar SO answer看看这个回复,这是非常相似的SO答案
But, you can simply wrap the dataset = fetch_mldata('MNIST original')
in a try-except block.但是,您可以简单地将
dataset = fetch_mldata('MNIST original')
包装在 try-except 块中。
try:
dataset = fetch_mldata('MNIST original')
except ConnectionResetError as exc:
print('Oh no, conection error', str(exc))
raise
This will catch the exception, print a statement, and then reraise the original exception.这将捕获异常,打印一条语句,然后重新引发原始异常。
This is the exception being raised socket.py You can try calling socket.settimeout with a larger timeout value to give your request time to complete.这是引发的异常socket.py您可以尝试使用更大的超时值调用socket.settimeout以使您的请求有时间完成。 To be clear, this will make the exception take even longer to appear (60 seconds in the code below).
需要明确的是,这将使异常出现的时间更长(在下面的代码中为 60 秒)。 If it still occurs, there may be an issue with your network that is causing a disconnect.
如果仍然出现,则可能是您的网络存在导致断开连接的问题。
from sklearn.datasets import fetch_mldata
import socket
socket.settimeout(60) # sets the socket timeout to 60 seconds.
dataset = fetch_mldata('MNIST original')
data = dataset.data
Another caveat, take a look at the first line of the error response you provided.另一个警告,请查看您提供的错误响应的第一行。
/usr/local/lib/python3.6/dist-packages/sklearn/utils/deprecation.py:85: DeprecationWarning: Function fetch_mldata is deprecated; fetch_mldata was deprecated in version 0.20 and will be removed in version 0.22. Please use fetch_openml.
warnings.warn(msg, category=DeprecationWarning) warnings.warn(味精,类别=弃用警告)
You may want to try using fetch_openml
since fetch_mldata
is being deprecated.您可能想尝试使用
fetch_openml
,因为fetch_mldata
已被弃用。
The MNIST dataset is removed from the sklearn. MNIST 数据集从 sklearn 中删除。 That is why I was facing that problem.
这就是我面临这个问题的原因。 Following is an alternate solution to load MNIST data:
以下是加载 MNIST 数据的替代解决方案:
from sklearn.datasets import fetch_mldata
mnist = fetch_mldata('MNIST original')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.