urllib.error — Exception classes raised by urllib.request

Вихідний код: Lib/urllib/error.py


Модуль urllib.error визначає класи винятків для винятків, викликаних urllib.request. Базовим класом винятків є URLError.

Наступні винятки викликаються urllib.error відповідно:

exception urllib.error.URLError

Обробники викликають цей виняток (або похідні виключення), коли стикаються з проблемою. Це підклас OSError.

reason

Причина цієї помилки. Це може бути рядок повідомлення або інший виняток.

Змінено в версії 3.3: URLError used to be a subtype of IOError, which is now an alias of OSError.

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

Хоча HTTPError і є винятком (підкласом URLError),він також може функціонувати як невиключне значення, схоже на файл (те саме, що urlopen() повертає). Це корисно під час обробки екзотичних помилок HTTP, таких як запити на автентифікацію.

url

Contains the request URL. An alias for filename attribute.

code

Код статусу HTTP, як визначено в RFC 2616. Це числове значення відповідає значенню, знайденому в словнику кодів у http.server.BaseHTTPRequestHandler.responses.

reason

This is usually a string explaining the reason for this error. An alias for msg attribute.

headers

The HTTP response headers for the HTTP request that caused the HTTPError. An alias for hdrs attribute.

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)

This exception is raised when the urlretrieve() function detects that the amount of the downloaded data is less than the expected amount (given by the Content-Length header).

content

The downloaded (and supposedly truncated) data.