![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /proc/1544360/cwd/usr/share/doc/python3-docs/html/library/ |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="X-UA-Compatible" content="IE=Edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>21.9. urllib.error — Exception classes raised by urllib.request — Python 3.6.7 documentation</title> <link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <script type="text/javascript" src="../_static/sidebar.js"></script> <link rel="search" type="application/opensearchdescription+xml" title="Search within Python 3.6.7 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="21.10. urllib.robotparser — Parser for robots.txt" href="urllib.robotparser.html" /> <link rel="prev" title="21.8. urllib.parse — Parse URLs into components" href="urllib.parse.html" /> <link rel="shortcut icon" type="image/png" href="../_static/py.png" /> <link rel="canonical" href="https://docs.python.org/3/library/urllib.error.html" /> <script type="text/javascript" src="../_static/copybutton.js"></script> </head><body> <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="urllib.robotparser.html" title="21.10. urllib.robotparser — Parser for robots.txt" accesskey="N">next</a> |</li> <li class="right" > <a href="urllib.parse.html" title="21.8. urllib.parse — Parse URLs into components" accesskey="P">previous</a> |</li> <li><img src="../_static/py.png" alt="" style="vertical-align: middle; margin-top: -1px"/></li> <li><a href="https://www.python.org/">Python</a> »</li> <li> <a href="../index.html">3.6.7 Documentation</a> » </li> <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li> <li class="nav-item nav-item-2"><a href="internet.html" accesskey="U">21. Internet Protocols and Support</a> »</li> <li class="right"> <div class="inline-search" style="display: none" role="search"> <form class="inline-search" action="../search.html" method="get"> <input placeholder="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> <script type="text/javascript">$('.inline-search').show(0);</script> | </li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body" role="main"> <div class="section" id="module-urllib.error"> <span id="urllib-error-exception-classes-raised-by-urllib-request"></span><h1>21.9. <a class="reference internal" href="#module-urllib.error" title="urllib.error: Exception classes raised by urllib.request."><code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib.error</span></code></a> — Exception classes raised by urllib.request<a class="headerlink" href="#module-urllib.error" title="Permalink to this headline">¶</a></h1> <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.6/Lib/urllib/error.py">Lib/urllib/error.py</a></p> <hr class="docutils" /> <p>The <a class="reference internal" href="#module-urllib.error" title="urllib.error: Exception classes raised by urllib.request."><code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib.error</span></code></a> module defines the exception classes for exceptions raised by <a class="reference internal" href="urllib.request.html#module-urllib.request" title="urllib.request: Extensible library for opening URLs."><code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib.request</span></code></a>. The base exception class is <a class="reference internal" href="#urllib.error.URLError" title="urllib.error.URLError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">URLError</span></code></a>.</p> <p>The following exceptions are raised by <a class="reference internal" href="#module-urllib.error" title="urllib.error: Exception classes raised by urllib.request."><code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib.error</span></code></a> as appropriate:</p> <dl class="exception"> <dt id="urllib.error.URLError"> <em class="property">exception </em><code class="descclassname">urllib.error.</code><code class="descname">URLError</code><a class="headerlink" href="#urllib.error.URLError" title="Permalink to this definition">¶</a></dt> <dd><p>The handlers raise this exception (or derived exceptions) when they run into a problem. It is a subclass of <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a>.</p> <dl class="attribute"> <dt id="urllib.error.URLError.reason"> <code class="descname">reason</code><a class="headerlink" href="#urllib.error.URLError.reason" title="Permalink to this definition">¶</a></dt> <dd><p>The reason for this error. It can be a message string or another exception instance.</p> </dd></dl> <div class="versionchanged"> <p><span class="versionmodified">Changed in version 3.3: </span><a class="reference internal" href="#urllib.error.URLError" title="urllib.error.URLError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">URLError</span></code></a> has been made a subclass of <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> instead of <a class="reference internal" href="exceptions.html#IOError" title="IOError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">IOError</span></code></a>.</p> </div> </dd></dl> <dl class="exception"> <dt id="urllib.error.HTTPError"> <em class="property">exception </em><code class="descclassname">urllib.error.</code><code class="descname">HTTPError</code><a class="headerlink" href="#urllib.error.HTTPError" title="Permalink to this definition">¶</a></dt> <dd><p>Though being an exception (a subclass of <a class="reference internal" href="#urllib.error.URLError" title="urllib.error.URLError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">URLError</span></code></a>), an <a class="reference internal" href="#urllib.error.HTTPError" title="urllib.error.HTTPError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">HTTPError</span></code></a> can also function as a non-exceptional file-like return value (the same thing that <a class="reference internal" href="urllib.request.html#urllib.request.urlopen" title="urllib.request.urlopen"><code class="xref py py-func docutils literal notranslate"><span class="pre">urlopen()</span></code></a> returns). This is useful when handling exotic HTTP errors, such as requests for authentication.</p> <dl class="attribute"> <dt id="urllib.error.HTTPError.code"> <code class="descname">code</code><a class="headerlink" href="#urllib.error.HTTPError.code" title="Permalink to this definition">¶</a></dt> <dd><p>An HTTP status code as defined in <span class="target" id="index-0"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc2616.html"><strong>RFC 2616</strong></a>. This numeric value corresponds to a value found in the dictionary of codes as found in <a class="reference internal" href="http.server.html#http.server.BaseHTTPRequestHandler.responses" title="http.server.BaseHTTPRequestHandler.responses"><code class="xref py py-attr docutils literal notranslate"><span class="pre">http.server.BaseHTTPRequestHandler.responses</span></code></a>.</p> </dd></dl> <dl class="attribute"> <dt id="urllib.error.HTTPError.reason"> <code class="descname">reason</code><a class="headerlink" href="#urllib.error.HTTPError.reason" title="Permalink to this definition">¶</a></dt> <dd><p>This is usually a string explaining the reason for this error.</p> </dd></dl> <dl class="attribute"> <dt id="urllib.error.HTTPError.headers"> <code class="descname">headers</code><a class="headerlink" href="#urllib.error.HTTPError.headers" title="Permalink to this definition">¶</a></dt> <dd><p>The HTTP response headers for the HTTP request that caused the <a class="reference internal" href="#urllib.error.HTTPError" title="urllib.error.HTTPError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">HTTPError</span></code></a>.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 3.4.</span></p> </div> </dd></dl> </dd></dl> <dl class="exception"> <dt id="urllib.error.ContentTooShortError"> <em class="property">exception </em><code class="descclassname">urllib.error.</code><code class="descname">ContentTooShortError</code><span class="sig-paren">(</span><em>msg</em>, <em>content</em><span class="sig-paren">)</span><a class="headerlink" href="#urllib.error.ContentTooShortError" title="Permalink to this definition">¶</a></dt> <dd><p>This exception is raised when the <a class="reference internal" href="urllib.request.html#urllib.request.urlretrieve" title="urllib.request.urlretrieve"><code class="xref py py-func docutils literal notranslate"><span class="pre">urlretrieve()</span></code></a> function detects that the amount of the downloaded data is less than the expected amount (given by the <em>Content-Length</em> header). The <code class="xref py py-attr docutils literal notranslate"><span class="pre">content</span></code> attribute stores the downloaded (and supposedly truncated) data.</p> </dd></dl> </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="urllib.parse.html" title="previous chapter">21.8. <code class="docutils literal notranslate"><span class="pre">urllib.parse</span></code> — Parse URLs into components</a></p> <h4>Next topic</h4> <p class="topless"><a href="urllib.robotparser.html" title="next chapter">21.10. <code class="docutils literal notranslate"><span class="pre">urllib.robotparser</span></code> — Parser for robots.txt</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.6/Doc/library/urllib.error.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="urllib.robotparser.html" title="21.10. urllib.robotparser — Parser for robots.txt" >next</a> |</li> <li class="right" > <a href="urllib.parse.html" title="21.8. urllib.parse — Parse URLs into components" >previous</a> |</li> <li><img src="../_static/py.png" alt="" style="vertical-align: middle; margin-top: -1px"/></li> <li><a href="https://www.python.org/">Python</a> »</li> <li> <a href="../index.html">3.6.7 Documentation</a> » </li> <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li> <li class="nav-item nav-item-2"><a href="internet.html" >21. Internet Protocols and Support</a> »</li> <li class="right"> <div class="inline-search" style="display: none" role="search"> <form class="inline-search" action="../search.html" method="get"> <input placeholder="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> <script type="text/javascript">$('.inline-search').show(0);</script> | </li> </ul> </div> <div class="footer"> © <a href="../copyright.html">Copyright</a> 2001-2023, Python Software Foundation. <br /> The Python Software Foundation is a non-profit corporation. <a href="https://www.python.org/psf/donations/">Please donate.</a> <br /> Last updated on Dec 18, 2023. <a href="../bugs.html">Found a bug</a>? <br /> Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.7.6. </div> </body> </html>