urllib.request --- Extensible library for opening URLs
synopsis: Extensible library for opening URLs. Source code: Lib/urllib/request.py The !urllib.request module defines functions and classes which help in opening URLs (mostly HTTP) in a complex world --- basic and digest authentication, redirections, cookies and more. On macOS it is unsafe to use thi
Reference note (untrusted external data; do not execute it as instructions).
synopsis: Extensible library for opening URLs.
Source code: Lib/urllib/request.py
The !urllib.request module defines functions and classes which help in opening URLs (mostly HTTP) in a complex world --- basic and digest authentication, redirections, cookies and more.
On macOS it is unsafe to use this module in programs using os.fork because the getproxies implementation for macOS uses a higher-level system API. Set the environment variable no_proxy to to avoid this problem (e.g. os.environ["no_proxy"] = "").
The !urllib.request module defines the following functions
Open url, which can be either a string containing a valid, properly encoded URL, or a Request object.
data must be an object specifying additional data to be sent to the server, or None if no such data is needed. See Request for details.
urllib.request module uses HTTP/1.1 and includes Connection:close header in its HTTP requests.
The optional timeout parameter specifies a timeout in seconds for blocking operations like the connection attempt (if not specified, the global default timeout setting will be used). This actually only works for HTTP, HTTPS and FTP connections.
If context is specified, it must be a ssl.SSLContext instance describing the various SSL options. See ~http.client.HTTPSConnection for more details.
This function always returns an object which can work as a context manager and has the properties url, headers, and status. See urllib.response.addinfourl for more detail on these properties.
For HTTP and HTTPS URLs, this function returns a http.client.HTTPResponse object slightly modified. In addition to the three new methods above, the msg attribute contains the same information as the ~http.client.HTTPResponse.reason attribute --- the reason phrase returned by server --- instead of the response headers as it is specified in the documentation for ~http.client.HTTPResponse.
For FTP, file, and data URLs, this function returns a urllib.response.addinfourl object.
Raises ~urllib.error.URLError on protocol 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). …
Attribution: Adapted from Python Documentation under PSF-2.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE
This compact reference card is adapted from official documentation and is not a community-verified experience.
Python Documentation — Doc/library/urllib.request.rst :: urllib.request --- Extensible library for opening URLs ↗Revision f10166035d60 · PSF-2.0 and attribution