urllib.error
--- urllib.request が投げる例外¶
ソースコード: Lib/urllib/error.py
urllib.error
は urllib.request
によって投げられる例外を定義しています。基底クラスは URLError
です。
urllib.error
は必要に応じて以下の例外が送出します:
- exception urllib.error.URLError¶
ハンドラが何らかの問題に遭遇した場合、この例外 (またはこの例外から派生した例外)を送出します。この例外は
OSError
のサブクラスです。- reason¶
このエラーの理由。メッセージ文字列あるいは他の例外インスタンスです。
- exception urllib.error.HTTPError(url, code, msg, hdrs, fp)¶
HTTPError
は例外 (URLError
のサブクラス) ですが、同時に例外ではない file-like な戻り値を返す関数でもあります (urlopen()
の戻り値と同じです)。これは、例えばサーバからの認証リクエストのように、変わった 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.