A convenience, top-level request method. It uses a module-global ``PoolManager`` instance. Therefore, its side effects could be shared across dependencies relying on it. To avoid side effects create a new ``PoolManager`` instance and use it instead. The method does not accept low-le
(
method: str,
url: str,
*,
body: _TYPE_BODY | None = None,
fields: _TYPE_FIELDS | None = None,
headers: typing.Mapping[str, str] | None = None,
preload_content: bool | None = True,
decode_content: bool | None = True,
redirect: bool | None = True,
retries: Retry | bool | int | None = None,
timeout: Timeout | float | int | None = 3,
json: typing.Any | None = None,
)
| 115 | |
| 116 | |
| 117 | def request( |
| 118 | method: str, |
| 119 | url: str, |
| 120 | *, |
| 121 | body: _TYPE_BODY | None = None, |
| 122 | fields: _TYPE_FIELDS | None = None, |
| 123 | headers: typing.Mapping[str, str] | None = None, |
| 124 | preload_content: bool | None = True, |
| 125 | decode_content: bool | None = True, |
| 126 | redirect: bool | None = True, |
| 127 | retries: Retry | bool | int | None = None, |
| 128 | timeout: Timeout | float | int | None = 3, |
| 129 | json: typing.Any | None = None, |
| 130 | ) -> BaseHTTPResponse: |
| 131 | """ |
| 132 | A convenience, top-level request method. It uses a module-global ``PoolManager`` instance. |
| 133 | Therefore, its side effects could be shared across dependencies relying on it. |
| 134 | To avoid side effects create a new ``PoolManager`` instance and use it instead. |
| 135 | The method does not accept low-level ``**urlopen_kw`` keyword arguments. |
| 136 | |
| 137 | :param method: |
| 138 | HTTP request method (such as GET, POST, PUT, etc.) |
| 139 | |
| 140 | :param url: |
| 141 | The URL to perform the request on. |
| 142 | |
| 143 | :param body: |
| 144 | Data to send in the request body, either :class:`str`, :class:`bytes`, |
| 145 | an iterable of :class:`str`/:class:`bytes`, or a file-like object. |
| 146 | |
| 147 | :param fields: |
| 148 | Data to encode and send in the request body. |
| 149 | |
| 150 | :param headers: |
| 151 | Dictionary of custom headers to send, such as User-Agent, |
| 152 | If-None-Match, etc. |
| 153 | |
| 154 | :param bool preload_content: |
| 155 | If True, the response's body will be preloaded into memory. |
| 156 | |
| 157 | :param bool decode_content: |
| 158 | If True, will attempt to decode the body based on the |
| 159 | 'content-encoding' header. |
| 160 | |
| 161 | :param redirect: |
| 162 | If True, automatically handle redirects (status codes 301, 302, |
| 163 | 303, 307, 308). Each redirect counts as a retry. Disabling retries |
| 164 | will disable redirect, too. |
| 165 | |
| 166 | :param retries: |
| 167 | Configure the number of retries to allow before raising a |
| 168 | :class:`~urllib3.exceptions.MaxRetryError` exception. |
| 169 | |
| 170 | If ``None`` (default) will retry 3 times, see ``Retry.DEFAULT``. Pass a |
| 171 | :class:`~urllib3.util.retry.Retry` object for fine-grained control |
| 172 | over different types of retries. |
| 173 | Pass an integer number to retry connection errors that many times, |
| 174 | but no other types of errors. Pass zero to never retry. |