Skip to content
Myr

Warn if cert / verify / trust_env are passed to client.request() (#597)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Add cert and verify warnings on Client.request * Resolve typo Co-Authored-By: Florimond Manca <florimond.manca@gmail.com> * Resolve typo Co-Authored-By: Florimond Manca <florimond.manca@gmail.com> * trust_env should be set on client init * Update docs for per-Client SSL settings * Update requests compat docs

authored by Tom Christie · committed by GitHub · parent c38fd68 · Browse files · 4 files+91 added−22 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+91 added−22 removed

  • other:+91 added−22 removed

4 files+91 added−22 removed

modified:docs/advanced.md+26 added-4 removed
172 unmodified lines
173174...175```176177When using `Client` instances, `trust_env` should be set on the client itself, rather that on the request methods:178179```python180client = httpx.Client(trust_env=False)181```182183## Unix Domain Sockets184185You can configure an `httpx` client to connect through a unix domain socket via the `uds` parameter. This is useful when making requests to a server that is bound to a socket file rather than an IP address.186
191 unmodified lines
378## SSL certificates379380When making a request over HTTPS, HTTPX needs to verify the identity of the requested host. To do this, it uses a bundle of SSL certificates (a.k.a. CA bundle) delivered by a trusted certificate authority (CA).381376### Default CA bundle382### Changing the verification defaults383384By default, HTTPX uses the CA bundle provided by [Certifi](https://pypi.org/project/certifi/). This is what you want in most cases, even though some advanced situations may require you to use a different set of certificates.385380### Using a custom CA bundle386If you'd like to use a custom CA bundle, you can use the `verify` parameter.387382If you'd like to use a custom CA bundle, you can use the `verify` parameter that is available on the high-level API as well as clients. For example:383388```python389import httpx390391r = await httpx.get("https://example.org", verify="path/to/client.pem")392```393394You can also disable the SSL verification...395396```python397import httpx398399r = await httpx.get("https://example.org", verify=False)400```401402### SSL configuration on client instances403404If you're using a `Client()` instance, then you should pass any SSL settings when instantiating the client.405406```python407client = httpx.Client(verify=False)408```409410The `client.get(...)` method and other request methods *do not* changing the SSL settings on a per-request basis. If you need different SSL settings in different cases you should use more that one client instance, with different settings on each. Each client will then be using an isolated connection pool with a specific fixed SSL configuration on all connections within that pool.411412### Making HTTPS requests to a local server413414When making requests to local servers, such as a development server running on `localhost`, you will typically be using unencrypted HTTP connections.415
65 unmodified lines
modified:docs/compatibility.md+43 added-12 removed
modified:docs/environment_variables.md+4 added-6 removed
1Environment Variables2=====================34The HTTPX library can be configured via environment variables.5Environment variables are used by default. To ignore environment variables, `trust_env` has to be set `False`.6There are two ways to set `trust_env` to disable environment variables:5Environment variables are used by default. To ignore environment variables, `trust_env` has to be set `False`. There are two ways to set `trust_env` to disable environment variables:68* On the client via `httpx.Client(trust_env=False)`9* Per request via `client.get("<url>", trust_env=False)`7* On the client via `httpx.Client(trust_env=False)`.8* Using the top-level API, such as `httpx.get("<url>", trust_env=False)`.911Here is a list of environment variables that HTTPX recognizes12and what function they serve:10Here is a list of environment variables that HTTPX recognizes and what function they serve:1112`HTTPX_LOG_LEVEL`13-----------------14
140 unmodified lines
modified:httpx/client.py+18 added
221 unmodified lines
222 verify: VerifyTypes = None,223 timeout: typing.Union[TimeoutTypes, UnsetType] = UNSET,224 trust_env: bool = None,225 ) -> Response:226 if cert is not None:227 warnings.warn(228 "Passing a 'cert' argument when making a request on a client "229 "is due to be deprecated. Instantiate a new client instead, "230 "passing any 'cert' arguments to the client itself."231 )232 if verify is not None:233 warnings.warn(234 "Passing a 'verify' argument when making a request on a client "235 "is due to be deprecated. Instantiate a new client instead, "236 "passing any 'verify' arguments to the client itself."237 )238 if trust_env is not None:239 warnings.warn(240 "Passing a 'trust_env' argument when making a request on a client "241 "is due to be deprecated. Instantiate a new client instead, "242 "passing any 'trust_env' argument to the client itself."243 )244 if stream:245 warnings.warn(246 "The 'stream=True' argument is due to be deprecated. "247 "Use 'async with client.stream(method, url, ...) as response' instead."
716 unmodified lines