parthtamu/rag-code-assistant
0
1<!DOCTYPE html>2 3<html lang="en" data-content_root="../">4 <head>5 <meta charset="utf-8" />6 <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />7<meta property="og:title" content="urllib.error — Exception classes raised by urllib.request" />8<meta property="og:type" content="website" />9<meta property="og:url" content="https://docs.python.org/3/library/urllib.error.html" />10<meta property="og:site_name" content="Python documentation" />11<meta property="og:description" content="Source code: Lib/urllib/error.py The urllib.error module defines the exception classes for exceptions raised by urllib.request. The base exception class is URLError. The following exceptions are ra..." />12<meta property="og:image:width" content="1146" />13<meta property="og:image:height" content="600" />14<meta property="og:image" content="https://docs.python.org/3.15/_images/social_previews/summary_library_urllib.error_78a3f9fd.png" />15<meta property="og:image:alt" content="Source code: Lib/urllib/error.py The urllib.error module defines the exception classes for exceptions raised by urllib.request. The base exception class is URLError. The following exceptions are ra..." />16<meta name="description" content="Source code: Lib/urllib/error.py The urllib.error module defines the exception classes for exceptions raised by urllib.request. The base exception class is URLError. The following exceptions are ra..." />17<meta name="twitter:card" content="summary_large_image" />18<meta name="theme-color" content="#3776ab">19 20 <title>urllib.error — Exception classes raised by urllib.request — Python 3.15.0a6 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">21 22 <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=b86133f3" />23 <link rel="stylesheet" type="text/css" href="../_static/classic.css?v=234b1a7c" />24 <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=89a2f22a" />25 <link rel="stylesheet" type="text/css" href="../_static/profiling-sampling-visualization.css?v=0c2600ae" />26 <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=5349f25f" />27 28 <script src="../_static/documentation_options.js?v=6b7c9ff5"></script>29 <script src="../_static/doctools.js?v=9bcbadda"></script>30 <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>31 <script src="../_static/profiling-sampling-visualization.js?v=9811ed04"></script>32 33 <script src="../_static/sidebar.js"></script>34 35 <link rel="search" type="application/opensearchdescription+xml"36 title="Search within Python 3.15.0a6 documentation"37 href="../_static/opensearch.xml"/>38 <link rel="author" title="About these documents" href="../about.html" />39 <link rel="index" title="Index" href="../genindex.html" />40 <link rel="search" title="Search" href="../search.html" />41 <link rel="copyright" title="Copyright" href="../copyright.html" />42 <link rel="next" title="urllib.robotparser — Parser for robots.txt" href="urllib.robotparser.html" />43 <link rel="prev" title="urllib.parse — Parse URLs into components" href="urllib.parse.html" />44 45 46 <script defer file-types="bz2,epub,zip" data-domain="docs.python.org" src="https://analytics.python.org/js/script.file-downloads.outbound-links.js"></script>47 48 <link rel="canonical" href="https://docs.python.org/3/library/urllib.error.html">49 50 51 52 53 <style>54 @media only screen {55 table.full-width-table {56 width: 100%;57 }58 }59 </style>60<link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">61 <link rel="shortcut icon" type="image/png" href="../_static/py.svg">62 <script type="text/javascript" src="../_static/copybutton.js"></script>63 <script type="text/javascript" src="../_static/menu.js"></script>64 <script type="text/javascript" src="../_static/search-focus.js"></script>65 <script type="text/javascript" src="../_static/themetoggle.js"></script> 66 <script type="text/javascript" src="../_static/rtd_switcher.js"></script>67 <meta name="readthedocs-addons-api-version" content="1">68 69 </head>70<body>71<div class="mobile-nav">72 <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"73 aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu">74 <nav class="nav-content" role="navigation">75 <label for="menuToggler" class="toggler__label">76 <span></span>77 </label>78 <span class="nav-items-wrapper">79 <a href="https://www.python.org/" class="nav-logo">80 <img src="../_static/py.svg" alt="Python logo">81 </a>82 <span class="version_switcher_placeholder"></span>83 <form role="search" class="search" action="../search.html" method="get">84 <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">85 <path fill-rule="nonzero" fill="currentColor" 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"></path>86 </svg>87 <input placeholder="Quick search" aria-label="Quick search" type="search" name="q">88 <input type="submit" value="Go">89 </form>90 </span>91 </nav>92 <div class="menu-wrapper">93 <nav class="menu" role="navigation" aria-label="main navigation">94 <div class="language_switcher_placeholder"></div>95 96<label class="theme-selector-label">97 Theme98 <select class="theme-selector" oninput="activateTheme(this.value)">99 <option value="auto" selected>Auto</option>100 <option value="light">Light</option>101 <option value="dark">Dark</option>102 </select>103</label>104 <div>105 <h4>Previous topic</h4>106 <p class="topless"><a href="urllib.parse.html"107 title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib.parse</span></code> — Parse URLs into components</a></p>108 </div>109 <div>110 <h4>Next topic</h4>111 <p class="topless"><a href="urllib.robotparser.html"112 title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib.robotparser</span></code> — Parser for robots.txt</a></p>113 </div>114 <script>115 document.addEventListener('DOMContentLoaded', () => {116 const title = document.querySelector('meta[property="og:title"]').content;117 const elements = document.querySelectorAll('.improvepage');118 const pageurl = window.location.href.split('?')[0];119 elements.forEach(element => {120 const url = new URL(element.href.split('?')[0].replace("-nojs", ""));121 url.searchParams.set('pagetitle', title);122 url.searchParams.set('pageurl', pageurl);123 url.searchParams.set('pagesource', "library/urllib.error.rst");124 element.href = url.toString();125 });126 });127 </script>128 <div role="note" aria-label="source link">129 <h3>This page</h3>130 <ul class="this-page-menu">131 <li><a href="../bugs.html">Report a bug</a></li>132 <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>133 <li>134 <a href="https://github.com/python/cpython/blob/main/Doc/library/urllib.error.rst?plain=1"135 rel="nofollow">Show source136 </a>137 </li>138 139 </ul>140 </div>141 </nav>142 </div>143</div>144 145 146 <div class="related" role="navigation" aria-label="Related">147 <h3>Navigation</h3>148 <ul>149 <li class="right" style="margin-right: 10px">150 <a href="../genindex.html" title="General Index"151 accesskey="I">index</a></li>152 <li class="right" >153 <a href="../py-modindex.html" title="Python Module Index"154 >modules</a> |</li>155 <li class="right" >156 <a href="urllib.robotparser.html" title="urllib.robotparser — Parser for robots.txt"157 accesskey="N">next</a> |</li>158 <li class="right" >159 <a href="urllib.parse.html" title="urllib.parse — Parse URLs into components"160 accesskey="P">previous</a> |</li>161 162 <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>163 <li><a href="https://www.python.org/">Python</a> »</li>164 <li class="switchers">165 <div class="language_switcher_placeholder"></div>166 <div class="version_switcher_placeholder"></div>167 </li>168 <li>169 170 </li>171 <li id="cpython-language-and-version">172 <a href="../index.html">3.15.0a6 Documentation</a> »173 </li>174 175 <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>176 <li class="nav-item nav-item-2"><a href="internet.html" accesskey="U">Internet Protocols and Support</a> »</li>177 <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib.error</span></code> — Exception classes raised by urllib.request</a></li>178 <li class="right">179 180 181 <div class="inline-search" role="search">182 <form class="inline-search" action="../search.html" method="get">183 <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">184 <input type="submit" value="Go">185 </form>186 </div>187 |188 </li>189 <li class="right">190<label class="theme-selector-label">191 Theme192 <select class="theme-selector" oninput="activateTheme(this.value)">193 <option value="auto" selected>Auto</option>194 <option value="light">Light</option>195 <option value="dark">Dark</option>196 </select>197</label> |</li>198 199 </ul>200 </div> 201 202 <div class="document">203 <div class="documentwrapper">204 <div class="bodywrapper">205 <div class="body" role="main">206 207 <section id="module-urllib.error">208<span id="urllib-error-exception-classes-raised-by-urllib-request"></span><h1><code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib.error</span></code> — Exception classes raised by urllib.request<a class="headerlink" href="#module-urllib.error" title="Link to this heading">¶</a></h1>209<p><strong>Source code:</strong> <a class="extlink-source reference external" href="https://github.com/python/cpython/tree/main/Lib/urllib/error.py">Lib/urllib/error.py</a></p>210<hr class="docutils" />211<p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib.error</span></code> module defines the exception classes for exceptions212raised 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>213<p>The following exceptions are raised by <code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib.error</span></code> as appropriate:</p>214<dl class="py exception">215<dt class="sig sig-object py" id="urllib.error.URLError">216<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">urllib.error.</span></span><span class="sig-name descname"><span class="pre">URLError</span></span><a class="headerlink" href="#urllib.error.URLError" title="Link to this definition">¶</a></dt>217<dd><p>The handlers raise this exception (or derived exceptions) when they run into218a 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>219<dl class="py attribute">220<dt class="sig sig-object py" id="urllib.error.URLError.reason">221<span class="sig-name descname"><span class="pre">reason</span></span><a class="headerlink" href="#urllib.error.URLError.reason" title="Link to this definition">¶</a></dt>222<dd><p>The reason for this error. It can be a message string or another223exception instance.</p>224</dd></dl>225 226<div class="versionchanged">227<p><span class="versionmodified changed">Changed in version 3.3: </span><code class="xref py py-exc docutils literal notranslate"><span class="pre">URLError</span></code> used to be a subtype 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>, which is now an228alias 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>229</div>230</dd></dl>231 232<dl class="py exception">233<dt class="sig sig-object py" id="urllib.error.HTTPError">234<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">urllib.error.</span></span><span class="sig-name descname"><span class="pre">HTTPError</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">url</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">code</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">msg</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">hdrs</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">fp</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#urllib.error.HTTPError" title="Link to this definition">¶</a></dt>235<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>), an236<code class="xref py py-exc docutils literal notranslate"><span class="pre">HTTPError</span></code> can also function as a non-exceptional file-like return237value (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). This238is useful when handling exotic HTTP errors, such as requests for239authentication.</p>240<dl class="py attribute">241<dt class="sig sig-object py" id="urllib.error.HTTPError.url">242<span class="sig-name descname"><span class="pre">url</span></span><a class="headerlink" href="#urllib.error.HTTPError.url" title="Link to this definition">¶</a></dt>243<dd><p>Contains the request URL.244An alias for <em>filename</em> attribute.</p>245</dd></dl>246 247<dl class="py attribute">248<dt class="sig sig-object py" id="urllib.error.HTTPError.code">249<span class="sig-name descname"><span class="pre">code</span></span><a class="headerlink" href="#urllib.error.HTTPError.code" title="Link to this definition">¶</a></dt>250<dd><p>An HTTP status code as defined in <span class="target" id="index-0"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc2616.html"><strong>RFC 2616</strong></a>. This numeric value corresponds251to a value found in the dictionary of codes as found in252<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>253</dd></dl>254 255<dl class="py attribute">256<dt class="sig sig-object py" id="urllib.error.HTTPError.reason">257<span class="sig-name descname"><span class="pre">reason</span></span><a class="headerlink" href="#urllib.error.HTTPError.reason" title="Link to this definition">¶</a></dt>258<dd><p>This is usually a string explaining the reason for this error.259An alias for <em>msg</em> attribute.</p>260</dd></dl>261 262<dl class="py attribute">263<dt class="sig sig-object py" id="urllib.error.HTTPError.headers">264<span class="sig-name descname"><span class="pre">headers</span></span><a class="headerlink" href="#urllib.error.HTTPError.headers" title="Link to this definition">¶</a></dt>265<dd><p>The HTTP response headers for the HTTP request that caused the266<code class="xref py py-exc docutils literal notranslate"><span class="pre">HTTPError</span></code>.267An alias for <em>hdrs</em> attribute.</p>268<div class="versionadded">269<p><span class="versionmodified added">Added in version 3.4.</span></p>270</div>271</dd></dl>272 273<dl class="py attribute">274<dt class="sig sig-object py" id="urllib.error.HTTPError.fp">275<span class="sig-name descname"><span class="pre">fp</span></span><a class="headerlink" href="#urllib.error.HTTPError.fp" title="Link to this definition">¶</a></dt>276<dd><p>A file-like object where the HTTP error body can be read from.</p>277</dd></dl>278 279</dd></dl>280 281<dl class="py exception">282<dt class="sig sig-object py" id="urllib.error.ContentTooShortError">283<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">urllib.error.</span></span><span class="sig-name descname"><span class="pre">ContentTooShortError</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">msg</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">content</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#urllib.error.ContentTooShortError" title="Link to this definition">¶</a></dt>284<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>285function detects that286the amount of the downloaded data is less than the expected amount (given by287the <em>Content-Length</em> header).</p>288<dl class="py attribute">289<dt class="sig sig-object py" id="urllib.error.ContentTooShortError.content">290<span class="sig-name descname"><span class="pre">content</span></span><a class="headerlink" href="#urllib.error.ContentTooShortError.content" title="Link to this definition">¶</a></dt>291<dd><p>The downloaded (and supposedly truncated) data.</p>292</dd></dl>293 294</dd></dl>295 296</section>297 298 299 <div class="clearer"></div>300 </div>301 </div>302 </div>303 <div class="sphinxsidebar" role="navigation" aria-label="Main">304 <div class="sphinxsidebarwrapper">305 <div>306 <h4>Previous topic</h4>307 <p class="topless"><a href="urllib.parse.html"308 title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib.parse</span></code> — Parse URLs into components</a></p>309 </div>310 <div>311 <h4>Next topic</h4>312 <p class="topless"><a href="urllib.robotparser.html"313 title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib.robotparser</span></code> — Parser for robots.txt</a></p>314 </div>315 <script>316 document.addEventListener('DOMContentLoaded', () => {317 const title = document.querySelector('meta[property="og:title"]').content;318 const elements = document.querySelectorAll('.improvepage');319 const pageurl = window.location.href.split('?')[0];320 elements.forEach(element => {321 const url = new URL(element.href.split('?')[0].replace("-nojs", ""));322 url.searchParams.set('pagetitle', title);323 url.searchParams.set('pageurl', pageurl);324 url.searchParams.set('pagesource', "library/urllib.error.rst");325 element.href = url.toString();326 });327 });328 </script>329 <div role="note" aria-label="source link">330 <h3>This page</h3>331 <ul class="this-page-menu">332 <li><a href="../bugs.html">Report a bug</a></li>333 <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>334 <li>335 <a href="https://github.com/python/cpython/blob/main/Doc/library/urllib.error.rst?plain=1"336 rel="nofollow">Show source337 </a>338 </li>339 340 </ul>341 </div>342 </div>343<div id="sidebarbutton" title="Collapse sidebar">344<span>«</span>345</div>346 347 </div>348 <div class="clearer"></div>349 </div> 350 <div class="related" role="navigation" aria-label="Related">351 <h3>Navigation</h3>352 <ul>353 <li class="right" style="margin-right: 10px">354 <a href="../genindex.html" title="General Index"355 >index</a></li>356 <li class="right" >357 <a href="../py-modindex.html" title="Python Module Index"358 >modules</a> |</li>359 <li class="right" >360 <a href="urllib.robotparser.html" title="urllib.robotparser — Parser for robots.txt"361 >next</a> |</li>362 <li class="right" >363 <a href="urllib.parse.html" title="urllib.parse — Parse URLs into components"364 >previous</a> |</li>365 366 <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>367 <li><a href="https://www.python.org/">Python</a> »</li>368 <li class="switchers">369 <div class="language_switcher_placeholder"></div>370 <div class="version_switcher_placeholder"></div>371 </li>372 <li>373 374 </li>375 <li id="cpython-language-and-version">376 <a href="../index.html">3.15.0a6 Documentation</a> »377 </li>378 379 <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>380 <li class="nav-item nav-item-2"><a href="internet.html" >Internet Protocols and Support</a> »</li>381 <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib.error</span></code> — Exception classes raised by urllib.request</a></li>382 <li class="right">383 384 385 <div class="inline-search" role="search">386 <form class="inline-search" action="../search.html" method="get">387 <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">388 <input type="submit" value="Go">389 </form>390 </div>391 |392 </li>393 <li class="right">394<label class="theme-selector-label">395 Theme396 <select class="theme-selector" oninput="activateTheme(this.value)">397 <option value="auto" selected>Auto</option>398 <option value="light">Light</option>399 <option value="dark">Dark</option>400 </select>401</label> |</li>402 403 </ul>404 </div> 405 <div class="footer">406 © <a href="../copyright.html">Copyright</a> 2001 Python Software Foundation.407 <br>408 This page is licensed under the Python Software Foundation License Version 2.409 <br>410 Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.411 <br>412 413 See <a href="/license.html">History and License</a> for more information.<br>414 415 416 <br>417 418 The Python Software Foundation is a non-profit corporation.419<a href="https://www.python.org/psf/donations/">Please donate.</a>420<br>421 <br>422 Last updated on Mar 10, 2026 (08:58 UTC).423 424 <a href="/bugs.html">Found a bug</a>?425 426 <br>427 428 Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.429 </div>430 431 </body>432</html>