python - python中的异常。给定定义,如何在代码中调用它?
问题描述
在库中定义了以下异常:
exception paramiko.ssh_exception.AuthenticationException
Exception raised when authentication failed for some reason. It may be possible to retry with different credentials. (Other classes specify more specific reasons.)
在我的代码中,如果我写:
except AuthenticationException:
我得到一个错误。
如果我写:
except paramiko.AuthenticationException:
有用。
为什么不:
except paramiko.ssh_exception.AuthenticationException:
给定定义,我怎么知道要写什么?
库 paramiko 显然是导入的:
import paramiko
解决方案
我猜paramiko
包有以下内容__init__.py
:
from .ssh_exception import *
然后如果你import paramiko
,你将拥有所有东西,paramiko
而无需额外的子分支
推荐阅读
- python - 当特定youtuber上传视频时,如何使discord bot在频道中发送消息
- xamarin.forms - 将命令传递给 ContentView 中的按钮
- python-3.x - Python:将二进制转换为十进制
- sql - 动态声明 FROM 要从哪个表名中选择
- python - 将文件作为python模块导入后从文件中删除锁(不卸载!)
- wpf - WPF:用户控件在设计时未在 ContentControl 的 Datatemplate 内显示
- java - 使用 while 循环重新运行程序后,异常方法不起作用
- r - 针织RMarkdown html_document中的Kable(kableExtra)垂直滚动条?
- java - android studio 中的 VINTF 清单是什么?有错误
- user-interface - 在用户登录 Firebase 和 SwiftUI 后创建配置文件