urllib.error — 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)

HTTPErrorURLError의 서브 클래스로 예외 클래스이긴 하지만, 예외가 아닌 파일류 반환 값(urlopen()의 반환 값과 동일한 값)으로도 작동할 수 있습니다. 이 방법은 인증 요청 같은 독특한(exotic) HTTP 에러를 처리할 때 유용합니다.

url

Contains the request URL. An alias for filename attribute.

code

RFC 2616에 정의된 HTTP 상태 코드입니다. 이 숫자 값은 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.

버전 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.