如何在 httpx python 中保持会话

how to persist sessions in httpx python

我们可以使用以下方法轻松创建持久会话:

s = requests.Session()

但是如何使用 httpx 库实现这一点?

async with httpx.AsyncClient() as client:
        response = await client.get(
            URL,
            params=params,
        )

像这样

with httpx.Client() as client:

    r = client.get('https://example.com')

来源https://www.python-httpx.org/advanced/