19.1.11. email.errors: 例外及び欠陥クラス

ソースコード: Lib/email/errors.py


email.errors モジュールでは、以下の例外クラスが定義されています:

exception email.errors.MessageError

これは email パッケージが送出しうるすべての例外の基底クラスです。これは標準の Exception クラスから派生しており、追加のメソッドは定義されていません。

exception email.errors.MessageParseError

This is the base class for exceptions raised by the Parser class. It is derived from MessageError.

exception email.errors.HeaderParseError

Raised under some error conditions when parsing the RFC 2822 headers of a message, this class is derived from MessageParseError. It can be raised from the Parser.parse or Parser.parsestr methods.

Situations where it can be raised include finding an envelope header after the first RFC 2822 header of the message, finding a continuation line before the first RFC 2822 header is found, or finding a line in the headers which is neither a header or a continuation line.

exception email.errors.BoundaryError

Raised under some error conditions when parsing the RFC 2822 headers of a message, this class is derived from MessageParseError. It can be raised from the Parser.parse or Parser.parsestr methods.

Situations where it can be raised include not being able to find the starting or terminating boundary in a multipart/* message when strict parsing is used.

exception email.errors.MultipartConversionError

この例外は、 Message オブジェクトに add_payload() メソッドでペイロードを追加したが、そのペイロードがすでにスカラー値で、メッセージの Content-Type メインタイプが multipart でないか見付からない場合に送出されます。 MultipartConversionErrorMessageError と組み込みの TypeError を多重継承しています。

Message.add_payload() は非推奨なので、実際のところこの例外が送出されることはほとんどありません。 しかしながら、 attach() メソッドを MIMENonMultipart から派生したインスタンス (たとえば MIMEImage) に対して呼んだ場合にも送出されることがあります。

Here's the list of the defects that the FeedParser can find while parsing messages. Note that the defects are added to the message where the problem was found, so for example, if a message nested inside a multipart/alternative had a malformed header, that nested message object would have a defect, but the containing messages would not.

All defect classes are subclassed from email.errors.MessageDefect, but this class is not an exception!

  • NoBoundaryInMultipartDefect -- メッセージが multipart だと宣言されているのに、 boundary パラメータがありません。

  • StartBoundaryNotFoundDefect -- Content-Type ヘッダで宣言された開始境界がありません。

  • CloseBoundaryNotFoundDefect -- 開始境界はあるが対応する終了境界がありません。

    バージョン 3.3 で追加.

  • FirstHeaderLineIsContinuationDefect -- メッセージの最初のヘッダ行が継続行です。

  • MisplacedEnvelopeHeaderDefect -- ヘッダブロックの途中に "Unix From" ヘッダがあります。

  • MissingHeaderBodySeparatorDefect - 先頭に空白はないが ':' がないヘッダの解析中に行が見付かりました。その行を本体の最初の行とみなして解析を続けます。

    バージョン 3.3 で追加.

  • MalformedHeaderDefect -- ヘッダにコロンがありません、あるいはそれ以外の不正な形式です。

    バージョン 3.3 で非推奨: この欠陥が使われていないPythonバージョンがいくつかあります。

  • MultipartInvariantViolationDefect -- メッセージが multipart だと宣言されているのに、サブパートが存在しません。 メッセージがこの欠陥を持つ場合、内容の型が multipart と宣言されていても is_multipart() メソッドは偽を返すことがあるので注意してください。

  • 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.

  • 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.