email.errors: 异常和缺陷类

源代码: Lib/email/errors.py


以下异常类在 email.errors 模块中定义:

exception email.errors.MessageError

这是 email 包可以引发的所有异常的基类。 它源自标准异常 Exception 类,这个类没有定义其他方法。

exception email.errors.MessageParseError

这是由 Parser 类引发的异常的基类。它派生自 MessageErrorheaderregistry 使用的解析器也在内部使用这个类。

exception email.errors.HeaderParseError

在解析消息的 RFC 5322 标头时,某些错误条件下会触发,此类派生自 MessageParseError。 如果在调用方法时内容类型未知,则 set_boundary() 方法将引发此错误。 当尝试创建一个看起来包含嵌入式标头的标头时 Header 可能会针对某些 base64 解码错误引发此错误(也就是说,应该是一个 没有前导空格并且看起来像标题的延续行)。

exception email.errors.BoundaryError

已弃用和不再使用的。

exception email.errors.MultipartConversionError

Raised 当 attach() 方法是在一个派生自 MIMENonMultipart 的类 (例如 MIMEImage) 的实例上被调用时会引发该异常。 MultipartConversionError 多重继承自 MessageError 和内置的 TypeError

exception email.errors.HeaderWriteError

generator 输出标头发生错误时将被引发。

exception email.errors.MessageDefect

这是表示在解析邮件消息时出现的所有错误的基类。 它派生自 ValueError

exception email.errors.HeaderDefect

这是表示在解析邮件标头时出现的所有错误的基类。 它派生自 MessageDefect

以下是 FeedParser 在解析消息时可发现的缺陷列表。 请注意这些缺陷会在问题被发现时加入到消息中,因此举例来说,如果某条嵌套在 multipart/alternative 中的消息具有错误的标头,该嵌套消息对象就会有一条缺陷,但外层消息对象则没有。

所有缺陷类都是 email.errors.MessageDefect 的子类。

exception email.errors.NoBoundaryInMultipartDefect

A message claimed to be a multipart, but had no boundary parameter.

exception email.errors.StartBoundaryNotFoundDefect

The start boundary claimed in the Content-Type header was never found.

exception email.errors.CloseBoundaryNotFoundDefect

A start boundary was found, but no corresponding close boundary was ever found.

Added in version 3.3.

exception email.errors.FirstHeaderLineIsContinuationDefect

The message had a continuation line as its first header line.

exception email.errors.MisplacedEnvelopeHeaderDefect

A "Unix From" header was found in the middle of a header block.

exception email.errors.MissingHeaderBodySeparatorDefect

A line was found while parsing headers that had no leading white space but contained no ':'. Parsing continues assuming that the line represents the first line of the body.

Added in version 3.3.

exception email.errors.MalformedHeaderDefect

A header was found that was missing a colon, or was otherwise malformed.

自 3.3 版本弃用: 此缺陷在近几个 Python 版本中已不再使用。

exception email.errors.MultipartInvariantViolationDefect

A message claimed to be a multipart, but no subparts were found. Note that when a message has this defect, its is_multipart() method may return False even though its content type claims to be multipart.

exception email.errors.InvalidBase64PaddingDefect

When decoding a block of base64 encoded bytes, the padding was not correct. Enough padding is added to perform the decode, but the resulting decoded bytes may be invalid.

exception email.errors.InvalidBase64CharactersDefect

When decoding a block of base64 encoded bytes, characters outside the base64 alphabet were encountered. The characters are ignored, but the resulting decoded bytes may be invalid.

exception email.errors.InvalidBase64LengthDefect

When decoding a block of base64 encoded bytes, the number of non-padding base64 characters was invalid (1 more than a multiple of 4). The encoded block was kept as-is.

exception email.errors.InvalidDateDefect

When decoding an invalid or unparsable date field. The original value is kept as-is.