email.errors: Exception and Defect classes¶
Вихідний код: Lib/email/errors.py
Наступні класи винятків визначено в модулі email.errors:
-
exception
email.errors.MessageError¶ Це базовий клас для всіх винятків, які може створити пакет
email. Він походить від стандартного класуExceptionі не визначає додаткових методів.
-
exception
email.errors.MessageParseError¶ Це базовий клас для винятків, викликаних класом
Parser. Він походить відMessageError. Цей клас також використовується внутрішньо аналізатором, який використовуєheaderregistry.
-
exception
email.errors.HeaderParseError¶ Виникає за деяких умов помилки під час аналізу заголовків RFC 5322 повідомлення, цей клас походить від
MessageParseError. Методset_boundary()викличе цю помилку, якщо під час виклику методу тип вмісту невідомий.Headerможе викликати цю помилку для певних помилок декодування base64, а також коли робиться спроба створити заголовок, який, здається, містить вбудований заголовок (тобто, є те, що має бути рядок продовження, який не має початкових пробілів і виглядає як заголовок).
-
exception
email.errors.BoundaryError¶ Застарілий і більше не використовується.
-
exception
email.errors.MultipartConversionError¶ Raised when a payload is added to a
Messageobject usingadd_payload(), but the payload is already a scalar and the message’s Content-Type main type is not either multipart or missing.MultipartConversionErrormultiply inherits fromMessageErrorand the built-inTypeError.Since
Message.add_payload()is deprecated, this exception is rarely raised in practice. However the exception may also be raised if theattach()method is called on an instance of a class derived fromMIMENonMultipart(e.g.MIMEImage).
-
exception
email.errors.HeaderWriteError¶ Raised when an error occurs when the
generatoroutputs headers.
Ось список дефектів, які FeedParser може знайти під час аналізу повідомлень. Зауважте, що дефекти додаються до повідомлення, у якому виявлено проблему, тому, наприклад, якщо повідомлення, вкладене в multipart/alternative, мало неправильний заголовок, цей вкладений об’єкт повідомлення мав би дефект, але містив би повідомлення не будуть.
Усі класи дефектів є підкласами email.errors.MessageDefect.
NoBoundaryInMultipartDefect– A message claimed to be a multipart, but had no boundary parameter.StartBoundaryNotFoundDefect– The start boundary claimed in the Content-Type header was never found.CloseBoundaryNotFoundDefect– A start boundary was found, but no corresponding close boundary was ever found.Нове в версії 3.3.
FirstHeaderLineIsContinuationDefect– The message had a continuation line as its first header line.MisplacedEnvelopeHeaderDefect- A «Unix From» header was found in the middle of a header block.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.Нове в версії 3.3.
MalformedHeaderDefect– A header was found that was missing a colon, or was otherwise malformed.Застаріло починаючи з версії 3.3: Цей дефект не використовувався для кількох версій Python.
MultipartInvariantViolationDefect– A message claimed to be a multipart, but no subparts were found. Note that when a message has this defect, itsis_multipart()method may returnFalseeven though its content type claims to be 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.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.