The urllib2 module defines functions and classes which help in opening URLs (mostly HTTP) in a complex world -- basic and digest authentication, redirections and more.
The urllib2 module defines the following functions:
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.
ProxyHandler, UnknownHandler, HTTPHandler, HTTPDefaultErrorHandler,
HTTPRedirectHandler, FTPHandler, FileHandler
If the Python installation has SSL support (socket.ssl() exists), HTTPSHandler will also be added.
The following exceptions are raised as appropriate:
The following classes are provided:
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.
(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.