Skip to content

Commit 3d3a088

Browse files
[PR #10301/77f25a0a backport][3.12] Update docs for aiohttp.request (#10308)
**This is a backport of PR #10301 as merged into master (77f25a0).** Co-authored-by: Cycloctane <[email protected]>
1 parent 52e4ea6 commit 3d3a088

File tree

1 file changed

+97
-28
lines changed

1 file changed

+97
-28
lines changed

docs/client_reference.rst

Lines changed: 97 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ The client session supports the context manager protocol for self closing.
517517
.. versionadded:: 3.0
518518

519519
:param str server_hostname: Sets or overrides the host name that the
520-
target servers certificate will be matched against.
520+
target server's certificate will be matched against.
521521

522522
See :py:meth:`asyncio.loop.create_connection` for more information.
523523

@@ -854,14 +854,21 @@ certification chaining.
854854

855855
.. function:: request(method, url, *, params=None, data=None, \
856856
json=None,\
857-
headers=None, cookies=None, auth=None, \
857+
cookies=None, headers=None, skip_auto_headers=None, auth=None, \
858858
allow_redirects=True, max_redirects=10, \
859-
encoding='utf-8', \
860-
version=HttpVersion(major=1, minor=1), \
861-
compress=None, chunked=None, expect100=False, raise_for_status=False, \
859+
compress=False, chunked=None, expect100=False, raise_for_status=None, \
860+
read_until_eof=True, \
861+
proxy=None, proxy_auth=None, \
862+
timeout=sentinel, ssl=True, \
863+
server_hostname=None, \
864+
proxy_headers=None, \
865+
trace_request_ctx=None, \
862866
read_bufsize=None, \
863-
connector=None, loop=None,\
864-
read_until_eof=True, timeout=sentinel)
867+
auto_decompress=None, \
868+
max_line_size=None, \
869+
max_field_size=None, \
870+
version=aiohttp.HttpVersion11, \
871+
connector=None)
865872
:async:
866873

867874
Asynchronous context manager for performing an asynchronous HTTP
@@ -874,8 +881,20 @@ certification chaining.
874881
be encoded with :class:`~yarl.URL` (see :class:`~yarl.URL`
875882
to skip encoding).
876883

877-
:param dict params: Parameters to be sent in the query
878-
string of the new request (optional)
884+
:param params: Mapping, iterable of tuple of *key*/*value* pairs or
885+
string to be sent as parameters in the query
886+
string of the new request. Ignored for subsequent
887+
redirected requests (optional)
888+
889+
Allowed values are:
890+
891+
- :class:`collections.abc.Mapping` e.g. :class:`dict`,
892+
:class:`multidict.MultiDict` or
893+
:class:`multidict.MultiDictProxy`
894+
- :class:`collections.abc.Iterable` e.g. :class:`tuple` or
895+
:class:`list`
896+
- :class:`str` with preferably url-encoded content
897+
(**Warning:** content will not be encoded by *aiohttp*)
879898

880899
:param data: The data to send in the body of the request. This can be a
881900
:class:`FormData` object or anything that can be passed into
@@ -885,28 +904,46 @@ certification chaining.
885904
:param json: Any json compatible python object (optional). *json* and *data*
886905
parameters could not be used at the same time.
887906

907+
:param dict cookies: HTTP Cookies to send with the request (optional)
908+
888909
:param dict headers: HTTP Headers to send with the request (optional)
889910

890-
:param dict cookies: Cookies to send with the request (optional)
911+
:param skip_auto_headers: set of headers for which autogeneration
912+
should be skipped.
913+
914+
*aiohttp* autogenerates headers like ``User-Agent`` or
915+
``Content-Type`` if these headers are not explicitly
916+
passed. Using ``skip_auto_headers`` parameter allows to skip
917+
that generation.
918+
919+
Iterable of :class:`str` or :class:`~multidict.istr`
920+
(optional)
891921

892922
:param aiohttp.BasicAuth auth: an object that represents HTTP Basic
893923
Authorization (optional)
894924

895925
:param bool allow_redirects: Whether to process redirects or not.
896-
When ``True``, redirects are followed (up to ``max_redirects`` times)
897-
and logged into :attr:`ClientResponse.history` and ``trace_configs``.
898-
When ``False``, the original response is returned.
899-
``True`` by default (optional).
926+
When ``True``, redirects are followed (up to ``max_redirects`` times)
927+
and logged into :attr:`ClientResponse.history` and ``trace_configs``.
928+
When ``False``, the original response is returned.
929+
``True`` by default (optional).
900930

901-
:param aiohttp.protocol.HttpVersion version: Request HTTP version (optional)
931+
:param int max_redirects: Maximum number of redirects to follow.
932+
:exc:`TooManyRedirects` is raised if the number is exceeded.
933+
Ignored when ``allow_redirects=False``.
934+
``10`` by default.
902935

903936
:param bool compress: Set to ``True`` if request has to be compressed
904-
with deflate encoding.
905-
``False`` instructs aiohttp to not compress data.
937+
with deflate encoding. If `compress` can not be combined
938+
with a *Content-Encoding* and *Content-Length* headers.
906939
``None`` by default (optional).
907940

908941
:param int chunked: Enables chunked transfer encoding.
909-
``None`` by default (optional).
942+
It is up to the developer
943+
to decide how to chunk data streams. If chunking is enabled, aiohttp
944+
encodes the provided chunks in the "Transfer-encoding: chunked" format.
945+
If *chunked* is set, then the *Transfer-encoding* and *content-length*
946+
headers are disallowed. ``None`` by default (optional).
910947

911948
:param bool expect100: Expect 100-continue response from server.
912949
``False`` by default (optional).
@@ -920,28 +957,60 @@ certification chaining.
920957

921958
.. versionadded:: 3.4
922959

923-
:param aiohttp.BaseConnector connector: BaseConnector sub-class
924-
instance to support connection pooling.
925-
926960
:param bool read_until_eof: Read response until EOF if response
927961
does not have Content-Length header.
928962
``True`` by default (optional).
929963

964+
:param proxy: Proxy URL, :class:`str` or :class:`~yarl.URL` (optional)
965+
966+
:param aiohttp.BasicAuth proxy_auth: an object that represents proxy HTTP
967+
Basic Authorization (optional)
968+
969+
:param timeout: a :class:`ClientTimeout` settings structure, 300 seconds (5min)
970+
total timeout, 30 seconds socket connect timeout by default.
971+
972+
:param ssl: SSL validation mode. ``True`` for default SSL check
973+
(:func:`ssl.create_default_context` is used),
974+
``False`` for skip SSL certificate validation,
975+
:class:`aiohttp.Fingerprint` for fingerprint
976+
validation, :class:`ssl.SSLContext` for custom SSL
977+
certificate validation.
978+
979+
Supersedes *verify_ssl*, *ssl_context* and
980+
*fingerprint* parameters.
981+
982+
:param str server_hostname: Sets or overrides the host name that the
983+
target server's certificate will be matched against.
984+
985+
See :py:meth:`asyncio.loop.create_connection`
986+
for more information.
987+
988+
:param collections.abc.Mapping proxy_headers: HTTP headers to send to the proxy
989+
if the parameter proxy has been provided.
990+
991+
:param trace_request_ctx: Object used to give as a kw param for each new
992+
:class:`TraceConfig` object instantiated,
993+
used to give information to the
994+
tracers that is only available at request time.
995+
930996
:param int read_bufsize: Size of the read buffer (:attr:`ClientResponse.content`).
931997
``None`` by default,
932998
it means that the session global value is used.
933999

9341000
.. versionadded:: 3.7
9351001

936-
:param timeout: a :class:`ClientTimeout` settings structure, 300 seconds (5min)
937-
total timeout, 30 seconds socket connect timeout by default.
1002+
:param bool auto_decompress: Automatically decompress response body.
1003+
May be used to enable/disable auto decompression on a per-request basis.
9381004

939-
:param loop: :ref:`event loop<asyncio-event-loop>`
940-
used for processing HTTP requests.
941-
If param is ``None``, :func:`asyncio.get_event_loop`
942-
is used for getting default event loop.
1005+
:param int max_line_size: Maximum allowed size of lines in responses.
9431006

944-
.. deprecated:: 2.0
1007+
:param int max_field_size: Maximum allowed size of header fields in responses.
1008+
1009+
:param aiohttp.protocol.HttpVersion version: Request HTTP version,
1010+
``HTTP 1.1`` by default. (optional)
1011+
1012+
:param aiohttp.BaseConnector connector: BaseConnector sub-class
1013+
instance to support connection pooling. (optional)
9451014

9461015
:return ClientResponse: a :class:`client response <ClientResponse>` object.
9471016

0 commit comments

Comments
 (0)