Show Table of Contents
3.9. 错误处理
当错误发生时,软件开发套件会使用异常(exception)来标识这些错误。软件开发套件定义了除标准 Python 异常外的额外异常。这些异常位于
ovirtsdk.infrastructure.errors 模块中:
- ConnectionError
- 在传输层错误发生时出现。
- DisconnectedError
- 当试图在断开连接后使用 SDK 时出现。
- ImmutableError
- 当一个 SDK 实例已经在相同的域中存在时初始 SDK 会出现这个错误。只适用于 SDK 3.2 或更高版本。
- NoCertificatesError
- 当 --insecure 是 'False',而没有提供 CA 时出现。
- RequestError
- 在有 oVirt 服务器错误时出现
- UnsecuredConnectionAttemptError
- 当服务器运行 HTTPS 而使用 HTTP 时出现。
- MissingParametersError
- 在没有为 get() 方法提供 id 或 name 参数的情况下出现。
这些异常的捕获和处理方法与其它 Python 异常的捕获和处理方法完全相同:
例 3.9. 捕获一个 ConnectionError 异常
from ovirtsdk.api import API
from ovirtsdk.xml import params
try:
api = API(url="https://HOST",
user="USER,
pass="PASS,
ca_file="/etc/pki/ovirt-engine/ca.pem")
except ConnectionError, err:
print "Connection failed: %s" % err
Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.