From 03d83b082fce200ddece85de1dbcb2232bcb885c Mon Sep 17 00:00:00 2001 From: Jian Zeng Date: Fri, 31 Aug 2018 18:36:40 +0800 Subject: [PATCH] Add timeout argument to aiohttp.client.request and bypass it to ClientSession PR #3213 by @knight42 * feat: specify timeout in aiohttp.request * doc: add myself to contributors * doc: add 3213.feature in CHANGES --- CHANGES/3213.feature | 1 + CONTRIBUTORS.txt | 1 + aiohttp/client.py | 5 ++++- docs/client_reference.rst | 5 ++++- 4 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 CHANGES/3213.feature diff --git a/CHANGES/3213.feature b/CHANGES/3213.feature new file mode 100644 index 00000000000..5645d6a391d --- /dev/null +++ b/CHANGES/3213.feature @@ -0,0 +1 @@ +Enable users to set `ClientTimeout` in `aiohttp.request` diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 147d8cb996c..3c5ebb9fe50 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -103,6 +103,7 @@ Jashandeep Sohi Jeongkyu Shin Jeroen van der Heijden Jesus Cea +Jian Zeng Jinkyu Yi Joel Watts Jon Nabozny diff --git a/aiohttp/client.py b/aiohttp/client.py index ec6e5a5bae8..73438f90927 100644 --- a/aiohttp/client.py +++ b/aiohttp/client.py @@ -906,6 +906,7 @@ def request(method, url, *, connector=None, loop=None, read_until_eof=True, + timeout=sentinel, proxy=None, proxy_auth=None) -> _SessionRequestContextManager: """Constructs and sends a request. Returns response object. @@ -933,6 +934,8 @@ def request(method, url, *, read_until_eof - Read response until eof if response does not have Content-Length header. loop - Optional event loop. + timeout - Optional ClientTimeout settings structure, 5min + total timeout by default. Usage:: >>> import aiohttp >>> resp = await aiohttp.request('GET', 'http://python.org/') @@ -946,7 +949,7 @@ def request(method, url, *, connector = TCPConnector(loop=loop, force_close=True) session = ClientSession( - loop=loop, cookies=cookies, version=version, + loop=loop, cookies=cookies, version=version, timeout=timeout, connector=connector, connector_owner=connector_owner) return _SessionRequestContextManager( diff --git a/docs/client_reference.rst b/docs/client_reference.rst index dfeda51f7b7..303c7845456 100644 --- a/docs/client_reference.rst +++ b/docs/client_reference.rst @@ -660,7 +660,7 @@ certification chaining. version=HttpVersion(major=1, minor=1), \ compress=None, chunked=None, expect100=False, raise_for_status=None, \ connector=None, loop=None,\ - read_until_eof=True) + read_until_eof=True, timeout=sentinel) :async-with: @@ -719,6 +719,9 @@ certification chaining. does not have Content-Length header. ``True`` by default (optional). + :param timeout: a :class:`ClientTimeout` settings structure, 5min + total timeout by default. + :param loop: :ref:`event loop` used for processing HTTP requests. If param is ``None``, :func:`asyncio.get_event_loop`