urllib.request.Request()
urllib.request.Request() is a Python function in the Urllib Module category. Creates an HTTP request with custom headers and method. The syntax is urllib.request.Request(url, data=None, headers={}, origin_req_host=None, unverifiable=False, method=None). Returns: Request object. A typical example: req = urllib.request.Request(
"https://api.example.com",
headers={"Authorization": "Bearer token123"},
method="GET"
)
with urlopen(req) as r:
print(r.read()). A close sibling is urllib.request.urlopen(), which opens a URL for reading (like GET request). Returns a file-like response object. 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.urlopen(), urllib.parse.urlparse(), urllib.parse.urlencode(), urllib.parse.urljoin(), urllib.parse.quote(), urllib.parse.unquote().