async def test_client_session_timeout_zero() -> None: timeout = client.ClientTimeout(total=10, connect=0, sock_connect=0, sock_read=0) try: async with ClientSession(timeout=timeout) as session: await session.get("http://example.com") except asyncio.TimeoutError: pytest.fail("0 should disable timeout.")
def test_client_session_timeout_args(loop) -> None: session1 = ClientSession(loop=loop) assert session1._timeout == client.DEFAULT_TIMEOUT session2 = ClientSession(loop=loop, read_timeout=20*60, conn_timeout=30*60) assert session2._timeout == client.ClientTimeout(total=20*60, connect=30*60) with pytest.raises(ValueError): ClientSession(loop=loop, timeout=client.ClientTimeout(total=10*60), read_timeout=20*60) with pytest.raises(ValueError): ClientSession(loop=loop, timeout=client.ClientTimeout(total=10 * 60), conn_timeout=30 * 60)
def __init__( self, timeout: float, default_headers: Mapping[str, str], loop: Optional[asyncio.AbstractEventLoop] = None, ): super().__init__(timeout, default_headers, loop) if isinstance(self.timeout, float): self._timeout = client.ClientTimeout(total=self.timeout) else: self._timeout = client.DEFAULT_TIMEOUT
def new_http_session(api_hash: str, timeout: float or int = None, *, ctype: str = None, atype: str = None): """ Create new instance of ClientSession :param api_hash: private key :param timeout: client timeout :param ctype: content-type :param atype: accept-type :return: aiohttp.client.ClientSession """ headers = { "Accept": atype or "application/json", "Content-type": ctype or "application/json", "Authorization": f"Bearer {api_hash}" if api_hash else None, } timeout = client.ClientTimeout(total=timeout or 60) return client.ClientSession(headers=params_filter(headers), timeout=timeout, json_serialize=serialize)