如何解决“ ConnectionResetError:[Errno 104]对等重置连接”错误?

时间:2019-09-13 14:43:59

标签: python scikit-learn google-colaboratory mnist

我正在尝试在google colaboratory的GPU上下载MNIST数据集。但是它向我显示“ ConnectionResetError:[Errno 104]对等重置连接”错误消息。

<div>
  <Field name="address">
      <div>
        <input
          value={this.state.address}
          onChange={this.onChange}
        />
      </div>
  </Field>
  <button onClick={this.onClear}>Clear</button>
</div>

我得到以下错误:

from sklearn.datasets import fetch_mldata
dataset = fetch_mldata('MNIST original')
data = dataset.data

显示此错误消息花费的时间太长。该如何解决?

2 个答案:

答案 0 :(得分:0)

看看这个响应,它非常类似于SO answer

但是,您可以简单地将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

这将捕获异常,打印一条语句,然后重新引发原始异常。

这是引发的异常socket.py,您可以尝试以较大的超时值调用socket.settimeout,以使请求时间完成。需要明确的是,这将使异常花费更长的时间(在下面的代码中为60秒)。如果仍然发生,则可能是网络问题导致断开连接。

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

另一个警告,请看一下您提供的错误响应的第一行。

/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)

由于不推荐使用fetch_openml,因此您可能想尝试使用fetch_mldata

答案 1 :(得分:0)

从sklearn中删除了MNIST数据集。这就是为什么我要面对这个问题。以下是加载MNIST数据的替代解决方案:

from sklearn.datasets import fetch_mldata
mnist = fetch_mldata('MNIST original')