environment_variables.md
This file
Path
docs/environment_variables.md
131 lines · 4.5 KiB · Markdown
Last changed by
Document client block-usage and close() (#487)Florimond Mancabefore adoption074cd25
History of this fileTake it
Add easier debug logging for users (#277)Seth Michael Larsonbefore adoption6f4f186
lines 1–4why, one step back1Environment Variables2=====================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 back5Environment 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)`10Add easier debug logging for users (#277)Seth Michael Larsonbefore adoption6f4f186
lines 11–29why, one step back11Here is a list of environment variables that HTTPX recognizes12and what function they serve:1314`HTTPX_DEBUG`15-----------1617Valid values: `1`, `true`1819If this environment variable is set to a valid value then low-level20details about the execution of HTTP requests will be logged to `stderr`.2122This can help you debug issues and see what's exactly being sent23over the wire and to which location.2425Example:2627```python28# test_script.py29import httpxDocument client block-usage and close() (#487)Florimond Mancabefore adoption074cd25
lines 30–32why, one step back3031with httpx.Client() as client:32 r = client.get("https://google.com")Add easier debug logging for users (#277)Seth Michael Larsonbefore adoption6f4f186
lines 33–52why, one step back33```3435```console36user@host:~$ HTTPX_DEBUG=1 python test_script.py3720:54:17.585 - httpx.dispatch.connection_pool - acquire_connection origin=Origin(scheme='https' host='www.google.com' port=443)3820:54:17.585 - httpx.dispatch.connection_pool - new_connection connection=HTTPConnection(origin=Origin(scheme='https' host='www.google.com' port=443))3920:54:17.590 - httpx.dispatch.connection - start_connect host='www.google.com' port=443 timeout=TimeoutConfig(timeout=5.0)4020:54:17.651 - httpx.dispatch.connection - connected http_version='HTTP/2'4120:54:17.651 - httpx.dispatch.http2 - send_headers stream_id=1 headers=[(b':method', b'GET'), (b':authority', b'www.google.com'), ...]4220:54:17.652 - httpx.dispatch.http2 - end_stream stream_id=14320:54:17.681 - httpx.dispatch.http2 - receive_event stream_id=0 event=<RemoteSettingsChanged changed_settings:{...}>4420:54:17.681 - httpx.dispatch.http2 - receive_event stream_id=0 event=<WindowUpdated stream_id:0, delta:983041>4520:54:17.682 - httpx.dispatch.http2 - receive_event stream_id=0 event=<SettingsAcknowledged changed_settings:{}>4620:54:17.739 - httpx.dispatch.http2 - receive_event stream_id=1 event=<ResponseReceived stream_id:1, headers:[(b':status', b'200'), ...]>4720:54:17.741 - httpx.dispatch.http2 - receive_event stream_id=1 event=<DataReceived stream_id:1, flow_controlled_length:5224 data:>4820:54:17.742 - httpx.dispatch.http2 - receive_event stream_id=1 event=<DataReceived stream_id:1, flow_controlled_length:59, data:>4920:54:17.742 - httpx.dispatch.http2 - receive_event stream_id=1 event=<StreamEnded stream_id:1>5020:54:17.742 - httpx.dispatch.http2 - receive_event stream_id=0 event=<PingReceived ping_data:0000000000000000>5120:54:17.743 - httpx.dispatch.connection_pool - release_connection connection=HTTPConnection(origin=Origin(scheme='https' host='www.google.com' port=443))52```Add support for SSLKEYLOGFILE (#301)Tomás Faríasbefore adoptiondb7f2d0
lines 53–67why, one step back5354`SSLKEYLOGFILE`55-----------5657Valid values: a filename5859If 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.6061Support for `SSLKEYLOGFILE` requires Python 3.8 and OpenSSL 1.1.1 or newer.6263Example:6465```python66# test_script.py67import httpxDocument client block-usage and close() (#487)Florimond Mancabefore adoption074cd25
lines 68–70why, one step back6869with httpx.Client() as client:70 r = client.get("https://google.com")Add support for SSLKEYLOGFILE (#301)Tomás Faríasbefore adoptiondb7f2d0
lines 71–86why, one step back71```7273```console74SSLKEYLOGFILE=test.log python test_script.py75cat test.log76# TLS secrets log file, generated by OpenSSL / Python77SERVER_HANDSHAKE_TRAFFIC_SECRET XXXX78EXPORTER_SECRET XXXX79SERVER_TRAFFIC_SECRET_0 XXXX80CLIENT_HANDSHAKE_TRAFFIC_SECRET XXXX81CLIENT_TRAFFIC_SECRET_0 XXXX82SERVER_HANDSHAKE_TRAFFIC_SECRET XXXX83EXPORTER_SECRET XXXX84SERVER_TRAFFIC_SECRET_0 XXXX85CLIENT_HANDSHAKE_TRAFFIC_SECRET XXXX86CLIENT_TRAFFIC_SECRET_0 XXXXAdd support for SSL_CERT_FILE and SSL_CERT_DIR (#307)Can Sarıgölbefore adoptionc9810a7
lines 87–116why, one step back87```8889`SSL_CERT_FILE`90-----------9192Valid values: a filename9394if this environment variable is set then HTTPX will load95CA certificate from the specified file instead of the default96location.9798Example:99100```console101SSL_CERT_FILE=/path/to/ca-certs/ca-bundle.crt python -c "import httpx; httpx.get('https://example.com')"102```103104`SSL_CERT_DIR`105-----------106107Valid values: a directory108109if this environment variable is set then HTTPX will load110CA certificates from the specified location instead of the default111location.112113Example:114115```console116SSL_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 117why, one step back117```Configure Proxy from Client (#353)Seth Michael Larsonbefore adoptionb0fa085
lines 118–131why, one step back118119`HTTP_PROXY`, `HTTPS_PROXY`, `ALL_PROXY`120----------------------------------------121122Valid values: A URL to a proxy123124Sets the proxy to be used for `http`, `https`, or all requests respectively.125126```bash127export HTTP_PROXY=http://127.0.0.1:3080128129# This request will be sent through the proxy130python -c "import httpx; httpx.get('http://example.com')"131```