企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
### 导航 - [索引](../genindex.xhtml "总目录") - [模块](../py-modindex.xhtml "Python 模块索引") | - [下一页](urllib.robotparser.xhtml "urllib.robotparser --- Parser for robots.txt") | - [上一页](urllib.parse.xhtml "urllib.parse --- Parse URLs into components") | - ![](https://box.kancloud.cn/a721fc7ec672275e257bbbfde49a4d4e_16x16.png) - [Python](https://www.python.org/) » - zh\_CN 3.7.3 [文档](../index.xhtml) » - [Python 标准库](index.xhtml) » - [互联网协议和支持](internet.xhtml) » - $('.inline-search').show(0); | # [`urllib.error`](#module-urllib.error "urllib.error: Exception classes raised by urllib.request.") --- Exception classes raised by urllib.request **Source code:** [Lib/urllib/error.py](https://github.com/python/cpython/tree/3.7/Lib/urllib/error.py) \[https://github.com/python/cpython/tree/3.7/Lib/urllib/error.py\] - - - - - - The [`urllib.error`](#module-urllib.error "urllib.error: Exception classes raised by urllib.request.") module defines the exception classes for exceptions raised by [`urllib.request`](urllib.request.xhtml#module-urllib.request "urllib.request: Extensible library for opening URLs."). The base exception class is [`URLError`](#urllib.error.URLError "urllib.error.URLError"). The following exceptions are raised by [`urllib.error`](#module-urllib.error "urllib.error: Exception classes raised by urllib.request.") as appropriate: *exception* `urllib.error.``URLError`The handlers raise this exception (or derived exceptions) when they run into a problem. It is a subclass of [`OSError`](exceptions.xhtml#OSError "OSError"). `reason`The reason for this error. It can be a message string or another exception instance. 在 3.3 版更改: [`URLError`](#urllib.error.URLError "urllib.error.URLError") has been made a subclass of [`OSError`](exceptions.xhtml#OSError "OSError") instead of [`IOError`](exceptions.xhtml#IOError "IOError"). *exception* `urllib.error.``HTTPError`Though being an exception (a subclass of [`URLError`](#urllib.error.URLError "urllib.error.URLError")), an [`HTTPError`](#urllib.error.HTTPError "urllib.error.HTTPError") can also function as a non-exceptional file-like return value (the same thing that [`urlopen()`](urllib.request.xhtml#urllib.request.urlopen "urllib.request.urlopen") returns). This is useful when handling exotic HTTP errors, such as requests for authentication. `code`An HTTP status code as defined in [**RFC 2616**](https://tools.ietf.org/html/rfc2616.html) \[https://tools.ietf.org/html/rfc2616.html\]. This numeric value corresponds to a value found in the dictionary of codes as found in [`http.server.BaseHTTPRequestHandler.responses`](http.server.xhtml#http.server.BaseHTTPRequestHandler.responses "http.server.BaseHTTPRequestHandler.responses"). `reason`This is usually a string explaining the reason for this error. `headers`The HTTP response headers for the HTTP request that caused the [`HTTPError`](#urllib.error.HTTPError "urllib.error.HTTPError"). 3\.4 新版功能. *exception* `urllib.error.``ContentTooShortError`(*msg*, *content*)This exception is raised when the [`urlretrieve()`](urllib.request.xhtml#urllib.request.urlretrieve "urllib.request.urlretrieve")function detects that the amount of the downloaded data is less than the expected amount (given by the *Content-Length* header). The `content` attribute stores the downloaded (and supposedly truncated) data. ### 导航 - [索引](../genindex.xhtml "总目录") - [模块](../py-modindex.xhtml "Python 模块索引") | - [下一页](urllib.robotparser.xhtml "urllib.robotparser --- Parser for robots.txt") | - [上一页](urllib.parse.xhtml "urllib.parse --- Parse URLs into components") | - ![](https://box.kancloud.cn/a721fc7ec672275e257bbbfde49a4d4e_16x16.png) - [Python](https://www.python.org/) » - zh\_CN 3.7.3 [文档](../index.xhtml) » - [Python 标准库](index.xhtml) » - [互联网协议和支持](internet.xhtml) » - $('.inline-search').show(0); | © [版权所有](../copyright.xhtml) 2001-2019, Python Software Foundation. Python 软件基金会是一个非盈利组织。 [请捐助。](https://www.python.org/psf/donations/) 最后更新于 5月 21, 2019. [发现了问题](../bugs.xhtml)? 使用[Sphinx](http://sphinx.pocoo.org/)1.8.4 创建。