马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
原文:Help on class ConnectionResetError in module builtins:
class ConnectionResetError(ConnectionError)
| Connection reset.
|
| Method resolution order:
| ConnectionResetError
| ConnectionError
| OSError
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from OSError:
|
| __reduce__(self, /)
| Helper for pickle.
|
| __str__(self, /)
| Return str(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from OSError:
|
| __new__(*args, **kwargs) class method of builtins.OSError
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from OSError:
|
| characters_written
|
| errno
| POSIX exception code
|
| filename
| exception filename
|
| filename2
| second exception filename
|
| strerror
| exception strerror
|
| winerror
| Win32 exception code
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(self, object, /)
|
| add_note(self, object, /)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(self, object, /)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
翻译:模块内置程序中 ConnectionResetError 类的帮助:
类 ConnectionResetError(ConnectionError)
| 重置连接。
|
| 方法解析顺序:
| 连接重置。
| 连接重置错误
| OSError
| 异常
| 基本异常
| 对象
|
| 这里定义的方法:
|
| __init__(self, /, *args, **kwargs)
| 初始化自身。 有关准确的签名,请参见 help(type(self)) 。
|
| ----------------------------------------------------------------------
| 继承自 OSError 的方法:
|
| __reduce__(self, /)
| 为 pickle 提供帮助。
|
| __str__(self, /)
| 返回 str(self)。
|
| ----------------------------------------------------------------------
| 继承自 OSError 的静态方法:
|
| buildins.OSError 的类方法 __new__(*args, **kwargs)
| 创建并返回一个新对象。 请参见 help(type) 获取准确的签名。
|
| ----------------------------------------------------------------------
| 从 OSError 继承的数据描述符:
|
| 字符写入
|
| Erno
| POSIX 异常代码
|
| 文件名
| 异常文件名
|
| 文件名2
| 第二个异常文件名
|
| stringerror
| 异常 strerror
|
| winerror
| Win32 异常代码
|
| ----------------------------------------------------------------------
| 继承自 BaseException 的方法:
|
| __getattribute__(self, name, /)
| 返回 getattr(self,name)。
|
| __repr__(self, /)
| 返回 repr(self)。
|
| 返回 __setstate__(self, object, /)
|
| add_note(self, object, /)
| Exception.add_note(note) --
| 为异常添加注释
|
| with_traceback(self, object, /)
| Exception.with_traceback(tb) -- | 为异常添加注释。
| 将 self.__traceback__ 设为 tb 并返回 self。
|
| ----------------------------------------------------------------------
| 从 BaseException 继承的数据描述符:
|
| __cause__
| 异常原因
|
| __context__
| 异常上下文
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
ConnectionResetError 的发生通常源于两种情况:
远程服务器的突然关闭: 服务器可能是因为遇到错误、过载或管理员手动干预而意外关闭连接。
中间设备的干预: 防火墙或其他网络安全设备可能会因连接可疑或危险而将其中断。
使用 retrying 库,我们能够为失败的操作设置自动重试机制。
import retrying
retry = retrying.Retry(
stop_max_attempt_number=3,
wait_fixed=2000
)
@retry
def make_request():
# 你的代码
以上示例中,我们创建了一个重试对象,它将尝试重试最多 3 次操作,每次重试之间间隔 2 秒。根据具体需要,你可以调整这些参数。通过使用 @retry 装饰器,我们将 make_request() 函数标记为具有自动重试功能,使其在遇到 ConnectionResetError 时自动重试。 |