上一话题

urllib.parse — 将 URL 剖析成组件

下一话题
就业培训     下载中心     Wiki     联络
登录   注册

Log
  1. 首页
  2. Python 3.12.4
  3. 索引
  4. 模块
  5. 下一
  6. 上一
  7. Python 标准库
  8. 互联网协议和支持
  9. urllib.error — 由 urllib.request 引发的异常类

urllib.error — 由 urllib.request 引发的异常类 ¶

源代码: 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 raised by urllib.error 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 .

reason ¶

The reason for this error. It can be a message string or another exception instance.

3.3 版改变: URLError used to be a subtype of IOError ,现在是别名化的 OSError .

exception urllib.error. HTTPError ( url , code , msg , hdrs , fp ) ¶

Though being an exception (a subclass of URLError ), an HTTPError can also function as a non-exceptional file-like return value (the same thing that urlopen() returns). This is useful when handling exotic HTTP errors, such as requests for authentication.

url ¶

Contains the request URL. An alias for filename 属性。

code ¶

An HTTP status code as defined in RFC 2616 . This numeric value corresponds to a value found in the dictionary of codes as found in http.server.BaseHTTPRequestHandler.responses .

reason ¶

This is usually a string explaining the reason for this error. An alias for msg 属性。

headers ¶

The HTTP response headers for the HTTP request that caused the HTTPError . An alias for hdrs 属性。

Added in version 3.4.

fp ¶

A file-like object where the HTTP error body can be read from.

exception urllib.error. ContentTooShortError ( msg , content ) ¶

此异常被引发当 urlretrieve() function detects that the amount of the downloaded data is less than the expected amount (given by the Content-Length 头)。

content ¶

The downloaded (and supposedly truncated) data.

上一话题

urllib.parse — 将 URL 剖析成组件

下一话题

urllib.robotparser — robots.txt 剖析器

本页

  • 报告 Bug
  • 展示源

快速搜索

键入搜索术语或模块、类、函数名称。

  1. 首页
  2. Python 3.12.4
  3. 索引
  4. 模块
  5. 下一
  6. 上一
  7. Python 标准库
  8. 互联网协议和支持
  9. urllib.error — 由 urllib.request 引发的异常类

版权所有  © 2014-2026 乐数软件    

工业和信息化部: 粤ICP备14079481号-1