The urllib2 module defines functions and classes which help in opening URLs (mostly HTTP) in a complex world -- basic and digest authentication, redirections, cookies and more.
The urllib2 module defines the following functions:
url[, data]) |
data should be a string, which specifies additional data to send to the server. In HTTP requests, which are the only ones that support data, it should be a buffer in the format of application/x-www-form-urlencoded, for example one returned from urllib.urlencode().
This function returns a file-like object with two additional methods:
Raises URLError on errors.
Note that None
may be returned if no handler handles the
request (though the default installed global OpenerDirector
uses UnknownHandler to ensure this never happens).
opener) |
[handler, ...]) |
If the Python installation has SSL support (socket.ssl() exists), HTTPSHandler will also be added.
Beginning in Python 2.3, a BaseHandler subclass may also
change its handler_order member variable to modify its
position in the handlers list. Besides ProxyHandler, which has
handler_order of 100
, all handlers currently have it
set to 500
.
The following exceptions are raised as appropriate:
The following classes are provided:
url[, data][, headers] [, origin_req_host][, unverifiable]) |
url should be a string which is a valid URL. For a description of data see the add_data() description. headers should be a dictionary, and will be treated as if add_header() was called with each key and value as arguments.
The final two arguments are only of interest for correct handling of third-party HTTP cookies:
origin_req_host should be the request-host of the origin
transaction, as defined by RFC 2965. It defaults to
cookielib.request_host(self)
. This is the host name or IP
address of the original request that was initiated by the user. For
example, if the request is for an image in an HTML document, this
should be the request-host of the request for the page containing the
image.
unverifiable should indicate whether the request is unverifiable, as defined by RFC 2965. It defaults to False. An unverifiable request is one whose URL the user did not have the option to approve. For example, if the request is for an image in an HTML document, and the user had no option to approve the automatic fetching of the image, this should be true.
) |
) |
) |
) |
[cookiejar]) |
[proxies]) |
) |
(realm, uri) -> (user, password)
mappings.
) |
(realm, uri) -> (user, password)
mappings.
A realm of None
is considered a catch-all realm, which is searched
if no other realm fits.
[password_mgr]) |
[password_mgr]) |
[password_mgr]) |
[password_mgr]) |
[password_mgr]) |
[password_mgr]) |
) |
) |
) |
) |
) |
) |
) |