Skip to content
Myr

environment_variables.md

This file

Path

docs/environment_variables.md

129 lines · 4.7 KiB · Markdown

Last changed by

Convert debug logs to trace logs (#500)Florimond Mancabefore adoption07586f9

History of this file

Take it

Add easier debug logging for users (#277)Seth Michael Larsonbefore adoption6f4f186

lines 1–4why, one step back
1Environment Variables
2=====================34The HTTPX library can be configured via environment variables.

Add support for SSL_CERT_FILE and SSL_CERT_DIR (#307)Can Sarıgölbefore adoptionc9810a7

lines 5–10why, one step back
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:78* On the client via `httpx.Client(trust_env=False)`9* Per request via `client.get("<url>", trust_env=False)`10

Add easier debug logging for users (#277)Seth Michael Larsonbefore adoption6f4f186

lines 11–13why, one step back
11Here is a list of environment variables that HTTPX recognizes
12and what function they serve:13

Convert debug logs to trace logs (#500)Florimond Mancabefore adoption07586f9

lines 14–15why, one step back
14`HTTPX_LOG_LEVEL`
15-----------------

Add easier debug logging for users (#277)Seth Michael Larsonbefore adoption6f4f186

line 16why, one step back
16

Convert debug logs to trace logs (#500)Florimond Mancabefore adoption07586f9

line 17why, one step back
17Valid values: `debug`, `trace` (case-insensitive)

Add easier debug logging for users (#277)Seth Michael Larsonbefore adoption6f4f186

line 18why, one step back
18

Convert debug logs to trace logs (#500)Florimond Mancabefore adoption07586f9

line 19why, one step back
19If set to `trace`, then low-level details about the execution of HTTP requests will be logged to `stderr`. This can help you debug issues and see what's exactly being sent over the wire and to which location.

Add easier debug logging for users (#277)Seth Michael Larsonbefore adoption6f4f186

line 20why, one step back
20

Convert debug logs to trace logs (#500)Florimond Mancabefore adoption07586f9

line 21why, one step back
21The `debug` log level is currently ignored, but is planned to issue high-level logs of HTTP requests.

Add easier debug logging for users (#277)Seth Michael Larsonbefore adoption6f4f186

lines 22–27why, one step back
22
23Example:2425```python26# test_script.py27import httpx

Document client block-usage and close() (#487)Florimond Mancabefore adoption074cd25

lines 28–30why, one step back
28
29with httpx.Client() as client:30 r = client.get("https://google.com")

Add easier debug logging for users (#277)Seth Michael Larsonbefore adoption6f4f186

lines 31–33why, one step back
31```
3233```console

Convert debug logs to trace logs (#500)Florimond Mancabefore adoption07586f9

line 34why, one step back
34user@host:~$ HTTPX_LOG_LEVEL=trace python test_script.py

Add easier debug logging for users (#277)Seth Michael Larsonbefore adoption6f4f186

lines 35–50why, one step back
3520:54:17.585 - httpx.dispatch.connection_pool - acquire_connection origin=Origin(scheme='https' host='www.google.com' port=443)
3620:54:17.585 - httpx.dispatch.connection_pool - new_connection connection=HTTPConnection(origin=Origin(scheme='https' host='www.google.com' port=443))3720:54:17.590 - httpx.dispatch.connection - start_connect host='www.google.com' port=443 timeout=TimeoutConfig(timeout=5.0)3820:54:17.651 - httpx.dispatch.connection - connected http_version='HTTP/2'3920:54:17.651 - httpx.dispatch.http2 - send_headers stream_id=1 headers=[(b':method', b'GET'), (b':authority', b'www.google.com'), ...]4020:54:17.652 - httpx.dispatch.http2 - end_stream stream_id=14120:54:17.681 - httpx.dispatch.http2 - receive_event stream_id=0 event=<RemoteSettingsChanged changed_settings:{...}>4220:54:17.681 - httpx.dispatch.http2 - receive_event stream_id=0 event=<WindowUpdated stream_id:0, delta:983041>4320:54:17.682 - httpx.dispatch.http2 - receive_event stream_id=0 event=<SettingsAcknowledged changed_settings:{}>4420:54:17.739 - httpx.dispatch.http2 - receive_event stream_id=1 event=<ResponseReceived stream_id:1, headers:[(b':status', b'200'), ...]>4520:54:17.741 - httpx.dispatch.http2 - receive_event stream_id=1 event=<DataReceived stream_id:1, flow_controlled_length:5224 data:>4620:54:17.742 - httpx.dispatch.http2 - receive_event stream_id=1 event=<DataReceived stream_id:1, flow_controlled_length:59, data:>4720:54:17.742 - httpx.dispatch.http2 - receive_event stream_id=1 event=<StreamEnded stream_id:1>4820:54:17.742 - httpx.dispatch.http2 - receive_event stream_id=0 event=<PingReceived ping_data:0000000000000000>4920:54:17.743 - httpx.dispatch.connection_pool - release_connection connection=HTTPConnection(origin=Origin(scheme='https' host='www.google.com' port=443))50```

Add support for SSLKEYLOGFILE (#301)Tomás Faríasbefore adoptiondb7f2d0

lines 51–65why, one step back
51
52`SSLKEYLOGFILE`53-----------5455Valid values: a filename5657If this environment variable is set, TLS keys will be appended to the specified file, creating it if it doesn't exist, whenever key material is generated or received. The keylog file is designed for debugging purposes only.5859Support for `SSLKEYLOGFILE` requires Python 3.8 and OpenSSL 1.1.1 or newer.6061Example:6263```python64# test_script.py65import httpx

Document client block-usage and close() (#487)Florimond Mancabefore adoption074cd25

lines 66–68why, one step back
66
67with httpx.Client() as client:68 r = client.get("https://google.com")

Add support for SSLKEYLOGFILE (#301)Tomás Faríasbefore adoptiondb7f2d0

lines 69–84why, one step back
69```
7071```console72SSLKEYLOGFILE=test.log python test_script.py73cat test.log74# TLS secrets log file, generated by OpenSSL / Python75SERVER_HANDSHAKE_TRAFFIC_SECRET XXXX76EXPORTER_SECRET XXXX77SERVER_TRAFFIC_SECRET_0 XXXX78CLIENT_HANDSHAKE_TRAFFIC_SECRET XXXX79CLIENT_TRAFFIC_SECRET_0 XXXX80SERVER_HANDSHAKE_TRAFFIC_SECRET XXXX81EXPORTER_SECRET XXXX82SERVER_TRAFFIC_SECRET_0 XXXX83CLIENT_HANDSHAKE_TRAFFIC_SECRET XXXX84CLIENT_TRAFFIC_SECRET_0 XXXX

Add support for SSL_CERT_FILE and SSL_CERT_DIR (#307)Can Sarıgölbefore adoptionc9810a7

lines 85–114why, one step back
85```
8687`SSL_CERT_FILE`88-----------8990Valid values: a filename9192if this environment variable is set then HTTPX will load93CA certificate from the specified file instead of the default94location.9596Example:9798```console99SSL_CERT_FILE=/path/to/ca-certs/ca-bundle.crt python -c "import httpx; httpx.get('https://example.com')"100```101102`SSL_CERT_DIR`103-----------104105Valid values: a directory106107if this environment variable is set then HTTPX will load108CA certificates from the specified location instead of the default109location.110111Example:112113```console114SSL_CERT_DIR=/path/to/ca-certs/ python -c "import httpx; httpx.get('https://example.com')"

Add support for SSLKEYLOGFILE (#301)Tomás Faríasbefore adoptiondb7f2d0

line 115why, one step back
115```

Configure Proxy from Client (#353)Seth Michael Larsonbefore adoptionb0fa085

lines 116–129why, one step back
116
117`HTTP_PROXY`, `HTTPS_PROXY`, `ALL_PROXY`118----------------------------------------119120Valid values: A URL to a proxy121122Sets the proxy to be used for `http`, `https`, or all requests respectively.123124```bash125export HTTP_PROXY=http://127.0.0.1:3080126127# This request will be sent through the proxy128python -c "import httpx; httpx.get('http://example.com')"129```