Skip to content

Commit 16e46f8

Browse files
authored
Merge branch 'master' into patch-1
2 parents 911198a + 4b23574 commit 16e46f8

File tree

5 files changed

+33
-17
lines changed

5 files changed

+33
-17
lines changed

docs/advanced/ssl.md

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,7 @@ client = httpx.Client(verify=ctx)
7171

7272
### Working with `SSL_CERT_FILE` and `SSL_CERT_DIR`
7373

74-
Unlike `requests`, the `httpx` package does not automatically pull in [the environment variables `SSL_CERT_FILE` or `SSL_CERT_DIR`](https://www.openssl.org/docs/manmaster/man3/SSL_CTX_set_default_verify_paths.html). If you want to use these they need to be enabled explicitly.
75-
76-
For example...
77-
78-
```python
79-
# Use `SSL_CERT_FILE` or `SSL_CERT_DIR` if configured.
80-
# Otherwise default to certifi.
81-
ctx = ssl.create_default_context(
82-
cafile=os.environ.get("SSL_CERT_FILE", certifi.where()),
83-
capath=os.environ.get("SSL_CERT_DIR"),
84-
)
85-
client = httpx.Client(verify=ctx)
86-
```
74+
`httpx` does respect the `SSL_CERT_FILE` and `SSL_CERT_DIR` environment variables by default. For details, refer to [the section on the environment variables page](../environment_variables.md#ssl_cert_file).
8775

8876
### Making HTTPS requests to a local server
8977

docs/compatibility.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,7 @@ For both query params (`params=`) and form data (`data=`), `requests` supports s
226226
In HTTPX, event hooks may access properties of requests and responses, but event hook callbacks cannot mutate the original request/response.
227227

228228
If you are looking for more control, consider checking out [Custom Transports](advanced/transports.md#custom-transports).
229+
230+
## Exceptions and Errors
231+
232+
`requests` exception hierarchy is slightly different to the `httpx` exception hierarchy. `requests` exposes a top level `RequestException`, where as `httpx` exposes a top level `HTTPError`. see the exceptions exposes in requests [here](https://requests.readthedocs.io/en/latest/_modules/requests/exceptions/). See the `httpx` error hierarchy [here](https://www.python-httpx.org/exceptions/).

docs/environment_variables.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,29 @@ python -c "import httpx; httpx.get('http://example.com')"
5151
python -c "import httpx; httpx.get('http://127.0.0.1:5000/my-api')"
5252
python -c "import httpx; httpx.get('https://www.python-httpx.org')"
5353
```
54+
55+
## `SSL_CERT_FILE`
56+
57+
Valid values: a filename
58+
59+
If this environment variable is set then HTTPX will load
60+
CA certificate from the specified file instead of the default
61+
location.
62+
63+
Example:
64+
65+
```console
66+
SSL_CERT_FILE=/path/to/ca-certs/ca-bundle.crt python -c "import httpx; httpx.get('https://example.com')"
67+
```
68+
69+
## `SSL_CERT_DIR`
70+
71+
Valid values: a directory following an [OpenSSL specific layout](https://www.openssl.org/docs/manmaster/man3/SSL_CTX_load_verify_locations.html).
72+
73+
If this environment variable is set and the directory follows an [OpenSSL specific layout](https://www.openssl.org/docs/manmaster/man3/SSL_CTX_load_verify_locations.html) (ie. you ran `c_rehash`) then HTTPX will load CA certificates from this directory instead of the default location.
74+
75+
Example:
76+
77+
```console
78+
SSL_CERT_DIR=/path/to/ca-certs/ python -c "import httpx; httpx.get('https://example.com')"
79+
```

docs/logging.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ httpx.get("https://www.example.com")
2020
Will send debug level output to the console, or wherever `stdout` is directed too...
2121

2222
```
23-
DEBUG [2024-09-28 17:27:40] httpx - load_ssl_context verify=True cert=None
24-
DEBUG [2024-09-28 17:27:40] httpx - load_verify_locations cafile='/Users/karenpetrosyan/oss/karhttpx/.venv/lib/python3.9/site-packages/certifi/cacert.pem'
2523
DEBUG [2024-09-28 17:27:40] httpcore.connection - connect_tcp.started host='www.example.com' port=443 local_address=None timeout=5.0 socket_options=None
2624
DEBUG [2024-09-28 17:27:41] httpcore.connection - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x101f1e8e0>
2725
DEBUG [2024-09-28 17:27:41] httpcore.connection - start_tls.started ssl_context=SSLContext(verify=True) server_hostname='www.example.com' timeout=5.0
@@ -80,4 +78,4 @@ logging.config.dictConfig(LOGGING_CONFIG)
8078
httpx.get('https://www.example.com')
8179
```
8280

83-
The exact formatting of the debug logging may be subject to change across different versions of `httpx` and `httpcore`. If you need to rely on a particular format it is recommended that you pin installation of these packages to fixed versions.
81+
The exact formatting of the debug logging may be subject to change across different versions of `httpx` and `httpcore`. If you need to rely on a particular format it is recommended that you pin installation of these packages to fixed versions.

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ cryptography==45.0.7
2323
mypy==1.17.1
2424
pytest==8.4.2
2525
ruff==0.12.11
26-
trio==0.30.0
26+
trio==0.31.0
2727
trio-typing==0.10.0
2828
trustme==1.2.1
2929
uvicorn==0.35.0

0 commit comments

Comments
 (0)