urllib.request.urlopen()
urllib.request.urlopen() is a Python function in the Urllib Module category. Opens a URL for reading (like GET request). Returns a file-like response object. The syntax is urllib.request.urlopen(url, data=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, *, cafile=None, capath=None, cadefault=False, context=None). Returns: HTTPResponse object. A typical example: from urllib.request import urlopen
with urlopen("https://api.example.com/data") as r:
data = r.read()
print(r.status, r.headers["Content-Type"]). A close sibling is urllib.request.Request(), which creates an HTTP request with custom headers and method. A close sibling is urllib.parse.urlparse(), which parses a URL into its components (scheme, netloc, path, params, query, fragment). A close sibling is urllib.parse.urlencode(), which encodes dictionary or sequence of pairs into a URL query string. A close sibling is urllib.parse.urljoin(), which constructs a full URL by combining a base URL with a relative URL. More about this category: URL handling — request, parse, urlopen, urlparse, urlencode, quote. Related Urllib Module entries: urllib.request.Request(), urllib.parse.urlparse(), urllib.parse.urlencode(), urllib.parse.urljoin(), urllib.parse.quote(), urllib.parse.unquote().