HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //usr/share/doc/python3-all/html/library/email.errors.html
<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

    <title>email.errors: Exception and Defect classes &#8212; Python 3.10.12 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
    
    <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?2022.1" />
    
    <script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
    <script src="../_static/jquery.js"></script>
    <script src="../_static/underscore.js"></script>
    <script src="../_static/doctools.js"></script>
    
    <script src="../_static/sidebar.js"></script>
    
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within Python 3.10.12 documentation"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="About these documents" href="../about.html" />
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="copyright" title="Copyright" href="../copyright.html" />
    <link rel="next" title="email.headerregistry: Custom Header Objects" href="email.headerregistry.html" />
    <link rel="prev" title="email.policy: Policy Objects" href="email.policy.html" />
    <link rel="canonical" href="file:///usr/share/doc/python3.10/html/library/email.errors.html" />
    
      
    

    
    <style>
      @media only screen {
        table.full-width-table {
            width: 100%;
        }
      }
    </style>
<link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
            <script type="text/javascript" src="../_static/copybutton.js"></script>
            <script type="text/javascript" src="../_static/menu.js"></script> 

  </head>
<body>
<div class="mobile-nav">
    <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
           aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
    <label for="menuToggler" class="toggler__label">
        <span></span>
    </label>
    <nav class="nav-content" role="navigation">
         <a href="https://www.python.org/" class="nav-logo">
             <img src="../_static/py.svg" alt="Logo"/>
         </a>
        <div class="version_switcher_placeholder"></div>
        <form role="search" class="search" action="../search.html" method="get">
            <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
                <path fill-rule="nonzero"
                        d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z" fill="#444"></path>
            </svg>
            <input type="text" name="q" aria-label="Quick search"/>
            <input type="submit" value="Go"/>
        </form>
    </nav>
    <div class="menu-wrapper">
        <nav class="menu" role="navigation" aria-label="main navigation">
            <div class="language_switcher_placeholder"></div>
  <h4>Previous topic</h4>
  <p class="topless"><a href="email.policy.html"
                        title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">email.policy</span></code>: Policy Objects</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="email.headerregistry.html"
                        title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">email.headerregistry</span></code>: Custom Header Objects</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../bugs.html">Report a Bug</a></li>
      <li>
        <a href="https://github.com/python/cpython/blob/3.10/Doc/library/email.errors.rst"
            rel="nofollow">Show Source
        </a>
      </li>
    </ul>
  </div>
        </nav>
    </div>
</div>

  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="email.headerregistry.html" title="email.headerregistry: Custom Header Objects"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="email.policy.html" title="email.policy: Policy Objects"
             accesskey="P">previous</a> |</li>

          <li><img src="../_static/py.svg" alt="python logo" style="vertical-align: middle; margin-top: -1px"/></li>
          <li><a href="https://www.python.org/">Python</a> &#187;</li>
          <li class="switchers">
            <div class="language_switcher_placeholder"></div>
            <div class="version_switcher_placeholder"></div>
          </li>
          <li>
              
          </li>
    <li id="cpython-language-and-version">
      <a href="../index.html">3.10.12 Documentation</a> &#187;
    </li>

          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="netdata.html" >Internet Data Handling</a> &#187;</li>
          <li class="nav-item nav-item-3"><a href="email.html" accesskey="U"><code class="xref py py-mod docutils literal notranslate"><span class="pre">email</span></code> — An email and MIME handling package</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">email.errors</span></code>: Exception and Defect classes</a></li>
                <li class="right">
                    

    <div class="inline-search" role="search">
        <form class="inline-search" action="../search.html" method="get">
          <input placeholder="Quick search" aria-label="Quick search" type="text" name="q" />
          <input type="submit" value="Go" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
                     |
                </li>
            
      </ul>
    </div>    

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="module-email.errors">
<span id="email-errors-exception-and-defect-classes"></span><h1><a class="reference internal" href="#module-email.errors" title="email.errors: The exception classes used by the email package."><code class="xref py py-mod docutils literal notranslate"><span class="pre">email.errors</span></code></a>: Exception and Defect classes<a class="headerlink" href="#module-email.errors" title="Permalink to this headline">¶</a></h1>
<p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.10/Lib/email/errors.py">Lib/email/errors.py</a></p>
<hr class="docutils" />
<p>The following exception classes are defined in the <a class="reference internal" href="#module-email.errors" title="email.errors: The exception classes used by the email package."><code class="xref py py-mod docutils literal notranslate"><span class="pre">email.errors</span></code></a> module:</p>
<dl class="py exception">
<dt class="sig sig-object py" id="email.errors.MessageError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">email.errors.</span></span><span class="sig-name descname"><span class="pre">MessageError</span></span><a class="headerlink" href="#email.errors.MessageError" title="Permalink to this definition">¶</a></dt>
<dd><p>This is the base class for all exceptions that the <a class="reference internal" href="email.html#module-email" title="email: Package supporting the parsing, manipulating, and generating email messages."><code class="xref py py-mod docutils literal notranslate"><span class="pre">email</span></code></a> package can
raise.  It is derived from the standard <a class="reference internal" href="exceptions.html#Exception" title="Exception"><code class="xref py py-exc docutils literal notranslate"><span class="pre">Exception</span></code></a> class and defines no
additional methods.</p>
</dd></dl>

<dl class="py exception">
<dt class="sig sig-object py" id="email.errors.MessageParseError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">email.errors.</span></span><span class="sig-name descname"><span class="pre">MessageParseError</span></span><a class="headerlink" href="#email.errors.MessageParseError" title="Permalink to this definition">¶</a></dt>
<dd><p>This is the base class for exceptions raised by the
<a class="reference internal" href="email.parser.html#email.parser.Parser" title="email.parser.Parser"><code class="xref py py-class docutils literal notranslate"><span class="pre">Parser</span></code></a> class.  It is derived from
<a class="reference internal" href="#email.errors.MessageError" title="email.errors.MessageError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">MessageError</span></code></a>.  This class is also used internally by the parser used
by <a class="reference internal" href="email.headerregistry.html#module-email.headerregistry" title="email.headerregistry: Automatic Parsing of headers based on the field name"><code class="xref py py-mod docutils literal notranslate"><span class="pre">headerregistry</span></code></a>.</p>
</dd></dl>

<dl class="py exception">
<dt class="sig sig-object py" id="email.errors.HeaderParseError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">email.errors.</span></span><span class="sig-name descname"><span class="pre">HeaderParseError</span></span><a class="headerlink" href="#email.errors.HeaderParseError" title="Permalink to this definition">¶</a></dt>
<dd><p>Raised under some error conditions when parsing the <span class="target" id="index-0"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc5322.html"><strong>RFC 5322</strong></a> headers of a
message, this class is derived from <a class="reference internal" href="#email.errors.MessageParseError" title="email.errors.MessageParseError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">MessageParseError</span></code></a>.  The
<a class="reference internal" href="email.message.html#email.message.EmailMessage.set_boundary" title="email.message.EmailMessage.set_boundary"><code class="xref py py-meth docutils literal notranslate"><span class="pre">set_boundary()</span></code></a> method will raise this
error if the content type is unknown when the method is called.
<a class="reference internal" href="email.header.html#email.header.Header" title="email.header.Header"><code class="xref py py-class docutils literal notranslate"><span class="pre">Header</span></code></a> may raise this error for certain base64
decoding errors, and when an attempt is made to create a header that appears
to contain an embedded header (that is, there is what is supposed to be a
continuation line that has no leading whitespace and looks like a header).</p>
</dd></dl>

<dl class="py exception">
<dt class="sig sig-object py" id="email.errors.BoundaryError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">email.errors.</span></span><span class="sig-name descname"><span class="pre">BoundaryError</span></span><a class="headerlink" href="#email.errors.BoundaryError" title="Permalink to this definition">¶</a></dt>
<dd><p>Deprecated and no longer used.</p>
</dd></dl>

<dl class="py exception">
<dt class="sig sig-object py" id="email.errors.MultipartConversionError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">email.errors.</span></span><span class="sig-name descname"><span class="pre">MultipartConversionError</span></span><a class="headerlink" href="#email.errors.MultipartConversionError" title="Permalink to this definition">¶</a></dt>
<dd><p>Raised when a payload is added to a <a class="reference internal" href="email.compat32-message.html#email.message.Message" title="email.message.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">Message</span></code></a> object
using <code class="xref py py-meth docutils literal notranslate"><span class="pre">add_payload()</span></code>, but the payload is already a scalar and the
message’s <em class="mailheader">Content-Type</em> main type is not either
<em class="mimetype">multipart</em> or missing.  <a class="reference internal" href="#email.errors.MultipartConversionError" title="email.errors.MultipartConversionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">MultipartConversionError</span></code></a> multiply
inherits from <a class="reference internal" href="#email.errors.MessageError" title="email.errors.MessageError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">MessageError</span></code></a> and the built-in <a class="reference internal" href="exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a>.</p>
<p>Since <code class="xref py py-meth docutils literal notranslate"><span class="pre">Message.add_payload()</span></code> is deprecated, this exception is rarely
raised in practice.  However the exception may also be raised if the
<a class="reference internal" href="email.compat32-message.html#email.message.Message.attach" title="email.message.Message.attach"><code class="xref py py-meth docutils literal notranslate"><span class="pre">attach()</span></code></a>
method is called on an instance of a class derived from
<a class="reference internal" href="email.mime.html#email.mime.nonmultipart.MIMENonMultipart" title="email.mime.nonmultipart.MIMENonMultipart"><code class="xref py py-class docutils literal notranslate"><span class="pre">MIMENonMultipart</span></code></a> (e.g.
<a class="reference internal" href="email.mime.html#email.mime.image.MIMEImage" title="email.mime.image.MIMEImage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MIMEImage</span></code></a>).</p>
</dd></dl>

<dl class="py exception">
<dt class="sig sig-object py" id="email.errors.HeaderWriteError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">email.errors.</span></span><span class="sig-name descname"><span class="pre">HeaderWriteError</span></span><a class="headerlink" href="#email.errors.HeaderWriteError" title="Permalink to this definition">¶</a></dt>
<dd><p>Raised when an error occurs when the <a class="reference internal" href="email.generator.html#module-email.generator" title="email.generator: Generate flat text email messages from a message structure."><code class="xref py py-mod docutils literal notranslate"><span class="pre">generator</span></code></a> outputs
headers.</p>
</dd></dl>

<p>Here is the list of the defects that the <a class="reference internal" href="email.parser.html#email.parser.FeedParser" title="email.parser.FeedParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">FeedParser</span></code></a>
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
<em class="mimetype">multipart/alternative</em> had a malformed header, that nested message
object would have a defect, but the containing messages would not.</p>
<p>All defect classes are subclassed from <code class="xref py py-class docutils literal notranslate"><span class="pre">email.errors.MessageDefect</span></code>.</p>
<ul>
<li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">NoBoundaryInMultipartDefect</span></code> – A message claimed to be a multipart,
but had no <em class="mimetype">boundary</em> parameter.</p></li>
<li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">StartBoundaryNotFoundDefect</span></code> – The start boundary claimed in the
<em class="mailheader">Content-Type</em> header was never found.</p></li>
<li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">CloseBoundaryNotFoundDefect</span></code> – A start boundary was found, but
no corresponding close boundary was ever found.</p>
<div class="versionadded">
<p><span class="versionmodified added">New in version 3.3.</span></p>
</div>
</li>
<li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">FirstHeaderLineIsContinuationDefect</span></code> – The message had a continuation
line as its first header line.</p></li>
<li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">MisplacedEnvelopeHeaderDefect</span></code> - A “Unix From” header was found in the
middle of a header block.</p></li>
<li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">MissingHeaderBodySeparatorDefect</span></code> - 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.</p>
<div class="versionadded">
<p><span class="versionmodified added">New in version 3.3.</span></p>
</div>
</li>
<li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">MalformedHeaderDefect</span></code> – A header was found that was missing a colon,
or was otherwise malformed.</p>
<div class="deprecated">
<p><span class="versionmodified deprecated">Deprecated since version 3.3: </span>This defect has not been used for several Python versions.</p>
</div>
</li>
<li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">MultipartInvariantViolationDefect</span></code> – A message claimed to be a
<em class="mimetype">multipart</em>, but no subparts were found.  Note that when a message
has this defect, its <a class="reference internal" href="email.compat32-message.html#email.message.Message.is_multipart" title="email.message.Message.is_multipart"><code class="xref py py-meth docutils literal notranslate"><span class="pre">is_multipart()</span></code></a> method may
return <code class="docutils literal notranslate"><span class="pre">False</span></code> even though its content type claims to be <em class="mimetype">multipart</em>.</p></li>
<li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">InvalidBase64PaddingDefect</span></code> – 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.</p></li>
<li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">InvalidBase64CharactersDefect</span></code> – 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.</p></li>
<li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">InvalidBase64LengthDefect</span></code> – 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.</p></li>
<li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">InvalidDateDefect</span></code> – When decoding an invalid or unparsable date field.
The original value is kept as-is.</p></li>
</ul>
</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h4>Previous topic</h4>
  <p class="topless"><a href="email.policy.html"
                        title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">email.policy</span></code>: Policy Objects</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="email.headerregistry.html"
                        title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">email.headerregistry</span></code>: Custom Header Objects</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../bugs.html">Report a Bug</a></li>
      <li>
        <a href="https://github.com/python/cpython/blob/3.10/Doc/library/email.errors.rst"
            rel="nofollow">Show Source
        </a>
      </li>
    </ul>
  </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="email.headerregistry.html" title="email.headerregistry: Custom Header Objects"
             >next</a> |</li>
        <li class="right" >
          <a href="email.policy.html" title="email.policy: Policy Objects"
             >previous</a> |</li>

          <li><img src="../_static/py.svg" alt="python logo" style="vertical-align: middle; margin-top: -1px"/></li>
          <li><a href="https://www.python.org/">Python</a> &#187;</li>
          <li class="switchers">
            <div class="language_switcher_placeholder"></div>
            <div class="version_switcher_placeholder"></div>
          </li>
          <li>
              
          </li>
    <li id="cpython-language-and-version">
      <a href="../index.html">3.10.12 Documentation</a> &#187;
    </li>

          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="netdata.html" >Internet Data Handling</a> &#187;</li>
          <li class="nav-item nav-item-3"><a href="email.html" ><code class="xref py py-mod docutils literal notranslate"><span class="pre">email</span></code> — An email and MIME handling package</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">email.errors</span></code>: Exception and Defect classes</a></li>
                <li class="right">
                    

    <div class="inline-search" role="search">
        <form class="inline-search" action="../search.html" method="get">
          <input placeholder="Quick search" aria-label="Quick search" type="text" name="q" />
          <input type="submit" value="Go" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
                     |
                </li>
            
      </ul>
    </div>  
    <div class="footer">
    &copy; <a href="../copyright.html">Copyright</a> 2001-2025, Python Software Foundation.
    <br />
    This page is licensed under the Python Software Foundation License Version 2.
    <br />
    Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
    <br />
    See <a href="/license.html">History and License</a> for more information.<br />
    <br />

    The Python Software Foundation is a non-profit corporation.
<a href="https://www.python.org/psf/donations/">Please donate.</a>
<br />
    <br />

    Last updated on August 15, 2025.
    <a href="/bugs.html">Found a bug</a>?
    <br />

    Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.3.2.
    </div>

  </body>
</html>