Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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/")
def test_timeout_from_config_instance():
timeout = httpx.Timeout(timeout=5.0)
assert httpx.Timeout(timeout) == httpx.Timeout(timeout=5.0)
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
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))
def test_timeout_from_one_none_value():
timeout = httpx.Timeout(read_timeout=None)
assert timeout == httpx.Timeout()
def test_timeout_from_none():
timeout = httpx.Timeout(timeout=None)
assert timeout == httpx.Timeout()
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)