Skip to content
Myr

environment_variables.md

This file

Path

docs/environment_variables.md

81 lines · 3.3 KiB · Markdown

Last changed by

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

History of this file

Take it

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

lines 1–46why, one step back
1Environment Variables
2=====================34The HTTPX library can be configured via environment variables.5Here is a list of environment variables that HTTPX recognizes6and what function they serve:78`HTTPX_DEBUG`9-----------1011Valid values: `1`, `true`1213If this environment variable is set to a valid value then low-level14details about the execution of HTTP requests will be logged to `stderr`.1516This can help you debug issues and see what's exactly being sent17over the wire and to which location.1819Example:2021```python22# test_script.py2324import httpx25client = httpx.Client()26client.get("https://google.com")27```2829```console30user@host:~$ HTTPX_DEBUG=1 python test_script.py3120:54:17.585 - httpx.dispatch.connection_pool - acquire_connection origin=Origin(scheme='https' host='www.google.com' port=443)3220:54:17.585 - httpx.dispatch.connection_pool - new_connection connection=HTTPConnection(origin=Origin(scheme='https' host='www.google.com' port=443))3320:54:17.590 - httpx.dispatch.connection - start_connect host='www.google.com' port=443 timeout=TimeoutConfig(timeout=5.0)3420:54:17.651 - httpx.dispatch.connection - connected http_version='HTTP/2'3520:54:17.651 - httpx.dispatch.http2 - send_headers stream_id=1 headers=[(b':method', b'GET'), (b':authority', b'www.google.com'), ...]3620:54:17.652 - httpx.dispatch.http2 - end_stream stream_id=13720:54:17.681 - httpx.dispatch.http2 - receive_event stream_id=0 event=<RemoteSettingsChanged changed_settings:{...}>3820:54:17.681 - httpx.dispatch.http2 - receive_event stream_id=0 event=<WindowUpdated stream_id:0, delta:983041>3920:54:17.682 - httpx.dispatch.http2 - receive_event stream_id=0 event=<SettingsAcknowledged changed_settings:{}>4020:54:17.739 - httpx.dispatch.http2 - receive_event stream_id=1 event=<ResponseReceived stream_id:1, headers:[(b':status', b'200'), ...]>4120:54:17.741 - httpx.dispatch.http2 - receive_event stream_id=1 event=<DataReceived stream_id:1, flow_controlled_length:5224 data:>4220:54:17.742 - httpx.dispatch.http2 - receive_event stream_id=1 event=<DataReceived stream_id:1, flow_controlled_length:59, data:>4320:54:17.742 - httpx.dispatch.http2 - receive_event stream_id=1 event=<StreamEnded stream_id:1>4420:54:17.742 - httpx.dispatch.http2 - receive_event stream_id=0 event=<PingReceived ping_data:0000000000000000>4520:54:17.743 - httpx.dispatch.connection_pool - release_connection connection=HTTPConnection(origin=Origin(scheme='https' host='www.google.com' port=443))46```

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

lines 47–81why, one step back
47
48`SSLKEYLOGFILE`49-----------5051Valid values: a filename5253If 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.5455Support for `SSLKEYLOGFILE` requires Python 3.8 and OpenSSL 1.1.1 or newer.5657Example:5859```python60# test_script.py6162import httpx63client = httpx.Client()64client.get("https://google.com")65```6667```console68SSLKEYLOGFILE=test.log python test_script.py69cat test.log70# TLS secrets log file, generated by OpenSSL / Python71SERVER_HANDSHAKE_TRAFFIC_SECRET XXXX72EXPORTER_SECRET XXXX73SERVER_TRAFFIC_SECRET_0 XXXX74CLIENT_HANDSHAKE_TRAFFIC_SECRET XXXX75CLIENT_TRAFFIC_SECRET_0 XXXX76SERVER_HANDSHAKE_TRAFFIC_SECRET XXXX77EXPORTER_SECRET XXXX78SERVER_TRAFFIC_SECRET_0 XXXX79CLIENT_HANDSHAKE_TRAFFIC_SECRET XXXX80CLIENT_TRAFFIC_SECRET_0 XXXX81```