How to use the httpx.Timeout function in httpx

To help you get started, weā€™ve selected a few httpx examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github encode / httpx / tests / test_timeouts.py View on Github external
async def test_connect_timeout(server):
    timeout = httpx.Timeout(connect_timeout=1e-6)

    async with httpx.Client(timeout=timeout) as client:
        with pytest.raises(httpx.ConnectTimeout):
            # See https://stackoverflow.com/questions/100841/
            await client.get("http://10.255.255.1/")
github encode / httpx / tests / test_config.py View on Github external
def test_timeout_from_config_instance():
    timeout = httpx.Timeout(timeout=5.0)
    assert httpx.Timeout(timeout) == httpx.Timeout(timeout=5.0)
github encode / httpx / tests / test_config.py View on Github external
def test_timeout_from_nothing():
    timeout = httpx.Timeout()
    assert timeout.connect_timeout is None
    assert timeout.read_timeout is None
    assert timeout.write_timeout is None
    assert timeout.pool_timeout is None
github encode / httpx / tests / test_config.py View on Github external
def test_timeout_from_one_value_and_default():
    timeout = httpx.Timeout(5.0, pool_timeout=60.0)
    assert timeout == httpx.Timeout(timeout=(5.0, 5.0, 5.0, 60.0))
github encode / httpx / tests / test_config.py View on Github external
def test_timeout_from_one_none_value():
    timeout = httpx.Timeout(read_timeout=None)
    assert timeout == httpx.Timeout()
github encode / httpx / tests / test_config.py View on Github external
def test_timeout_from_none():
    timeout = httpx.Timeout(timeout=None)
    assert timeout == httpx.Timeout()
github lilydjwg / nvchecker / nvchecker / source / httpx_httpclient.py View on Github external
def get(self, *args, **kwargs) -> ResponseManager:
    proxy = kwargs.pop('proxy', None)
    client = self.clients.get(proxy)
    if not client:
      client = httpx.AsyncClient(
        pool_limits = httpx.PoolLimits(
          max_keepalive = self.concurrency * 2,
          max_connections = self.concurrency,
        ),
        timeout = httpx.Timeout(20, pool_timeout=None),
        headers = {'User-Agent': DEFAULT_USER_AGENT},
        http2 = True,
        proxies = proxy,
      )
      self.clients[proxy] = client
    return ResponseManager(client, args, kwargs)