urllib

Open an arbitrary URL.

See the following document for more info on URLs: “Names and Addresses, URIs, URLs, URNs, URCs”, at http://www.w3.org/pub/WWW/Addressing/Overview.html

See also the HTTP spec (from which the error codes are derived): “HTTP - Hypertext Transfer Protocol”, at http://www.w3.org/pub/WWW/Protocols/

Related standards and specs: - RFC1808: the “relative URL” spec. (authoritative status) - RFC1738 - the “URL standard”. (authoritative status) - RFC1630 - the “URI spec”. (informational status)

The object returned by URLopener().open(file) will differ per protocol. All you know is that is has methods read(), readline(), readlines(), fileno(), close() and info(). The read*(), fileno() and close() methods work like those of open files. The info() method returns a mimetools.Message object which can be used to query various info about the object, if available. (mimetools.Message objects are queried with the getheader() method.)

Functions

basejoin(base, url[, allow_fragments]) Join a base URL and a possibly relative URL to form an absolute interpretation of the latter.
ftperrors() Return the set of errors raised by the FTP class.
getproxies() Return a dictionary of scheme -> proxy server URL mappings.
getproxies_environment() Return a dictionary of scheme -> proxy server URL mappings.
localhost() Return the IP address of the magic hostname ‘localhost’.
noheaders() Return an empty mimetools.Message object.
pathname2url(pathname) OS-specific conversion from a file system path to a relative URL of the ‘file’ scheme; not recommended for general use.
proxy_bypass(host[, proxies]) Test if proxies should not be used for a particular host.
proxy_bypass_environment(host[, proxies]) Test if proxies should not be used for a particular host.
quote(() -> ) Each part of a URL, e.g.
quote_plus(s[, safe]) Quote the query fragment of a URL; replacing ‘ ‘ with ‘+’
reporthook(blocknum, blocksize, totalsize)
splitattr() ‘/path’, [‘attr1=value1’, ‘attr2=value2’, ...].
splithost(url) splithost(‘//host[:port]/path’) –> ‘host[:port]’, ‘/path’.
splitnport(host[, defport]) Split host and port, returning numeric port.
splitpasswd(() -> , .)
splitport(host) splitport(‘host:port’) –> ‘host’, ‘port’.
splitquery(url) splitquery(‘/path?query’) –> ‘/path’, ‘query’.
splittag(url) splittag(‘/path#tag’) –> ‘/path’, ‘tag’.
splittype(url) splittype(‘type:opaquestring’) –> ‘type’, ‘opaquestring’.
splituser(host) splituser(‘user[:passwd]@host[:port]’) –> ‘user[:passwd]’, ‘host[:port]’.
splitvalue(attr) splitvalue(‘attr=value’) –> ‘attr’, ‘value’.
test1()
thishost() Return the IP address of the current host.
toBytes(url) toBytes(u”URL”) –> ‘URL’.
unquote(() -> .)
unquote_plus(s) unquote(‘%7e/abc+def’) -> ‘~/abc def’
unwrap(url) unwrap(‘<URL:type://host/path>’) –> ‘type://host/path’.
url2pathname(pathname) OS-specific conversion from a relative URL of the ‘file’ scheme to a file system path; not recommended for general use.
urlcleanup()
urlencode(query[, doseq]) Encode a sequence of two-element tuples or dictionary into a URL query string.
urlopen(url[, data, proxies, context]) Create a file-like object for the specified URL to read from.
urlretrieve(url[, filename, reporthook, ...])

Classes

FancyURLopener(*args, **kwargs) Derived class with handlers for errors we can handle (perhaps).
URLopener([proxies, context]) Class to open URLs.
addbase(fp) Base class for addinfo and addclosehook.
addclosehook(fp, closehook, *hookargs) Class to add a close hook to an open file.
addinfo(fp, headers) class to add an info() method to an open file.
addinfourl(fp, headers, url[, code]) class to add info() and geturl() methods to an open file.
ftpwrapper(user, passwd, host, port, dirs[, ...]) Class used by open_ftp() for cache of open FTP connections.

Exceptions

ContentTooShortError(message, content)