urllib3.request()¶
- urllib3.request(method, url, *, body=None, fields=None, headers=None, preload_content=True, decode_content=True, redirect=True, retries=None, timeout=3, json=None)¶
A convenience, top-level request method. It uses a module-global
PoolManagerinstance. Therefore, its side effects could be shared across dependencies relying on it. To avoid side effects create a newPoolManagerinstance and use it instead. The method does not accept low-level**urlopen_kwkeyword arguments.- Parameters:
method (str) – HTTP request method (such as GET, POST, PUT, etc.)
url (str) – The URL to perform the request on.
body (bytes | IO[Any] | Iterable[bytes | str] | str | None) – Data to send in the request body, either
str,bytes, an iterable ofstr/bytes, or a file-like object.fields (Sequence[tuple[str, str | bytes | tuple[str, str | bytes] | tuple[str, str | bytes, str]] | RequestField] | Mapping[str, str | bytes | tuple[str, str | bytes] | tuple[str, str | bytes, str]] | None) – Data to encode and send in the request body.
headers (Mapping[str, str] | None) – Dictionary of custom headers to send, such as User-Agent, If-None-Match, etc.
preload_content (bool) – If True, the response’s body will be preloaded into memory.
decode_content (bool) – If True, will attempt to decode the body based on the ‘content-encoding’ header.
redirect (bool | None) – If True, automatically handle redirects (status codes 301, 302, 303, 307, 308). Each redirect counts as a retry. Disabling retries will disable redirect, too.
retries (
Retry, False, or an int.) –Configure the number of retries to allow before raising a
MaxRetryErrorexception.If
None(default) will retry 3 times, seeRetry.DEFAULT. Pass aRetryobject for fine-grained control over different types of retries. Pass an integer number to retry connection errors that many times, but no other types of errors. Pass zero to never retry.If
False, then retries are disabled and any exception is raised immediately. Also, instead of raising a MaxRetryError on redirects, the redirect response will be returned.timeout (Timeout | float | int | None) – If specified, overrides the default timeout for this one request. It may be a float (in seconds) or an instance of
urllib3.util.Timeout.json (Any | None) – Data to encode and send as JSON with UTF-encoded in the request body. The
"Content-Type"header will be set to"application/json"unless specified otherwise.
- Return type: