Skip to content
Myr

environment_variables.md

This file

Path

docs/environment_variables.md

154 lines · 9.8 KiB · Markdown

Last changed by

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

History of this file

Take it

The walk stopped after 200 commits: lines older than 3065dd6 point at it.

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

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

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

line 5why, one step back
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:

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

line 6why, one step back
6

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

lines 7–8why, one step back
7* On the client via `httpx.Client(trust_env=False)`.
8* Using the top-level API, such as `httpx.get("<url>", trust_env=False)`.

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

line 9why, one step back
9

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

line 10why, one step back
10Here is a list of environment variables that HTTPX recognizes and what function they serve:

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

line 11why, one step back
11

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

lines 12–13why, one step back
12`HTTPX_LOG_LEVEL`
13-----------------

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

line 14why, one step back
14

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

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

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

line 16why, one step back
16

Add DEBUG logs of HTTP requests (#502)Florimond Mancabefore adoption08069e9

line 17why, one step back
17If set to `debug`, then HTTP requests will be logged to `stderr`. This is useful for general purpose reporting of network activity.

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

line 18why, one step back
18

Add DEBUG logs of HTTP requests (#502)Florimond Mancabefore adoption08069e9

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

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 20–25why, one step back
20
21Example:2223```python24# test_script.py25import httpx

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

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

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 29–30why, one step back
29```
30

Add DEBUG logs of HTTP requests (#502)Florimond Mancabefore adoption08069e9

lines 31–32why, one step back
31Debug output:
32

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

line 33why, one step back
33```console

Add DEBUG logs of HTTP requests (#502)Florimond Mancabefore adoption08069e9

lines 34–46why, one step back
34$ HTTPX_LOG_LEVEL=debug python test_script.py
35DEBUG [2019-11-06 19:11:24] httpx.client - HTTP Request: GET https://google.com "HTTP/1.1 301 Moved Permanently"36DEBUG [2019-11-06 19:11:24] httpx.client - HTTP Request: GET https://www.google.com/ "HTTP/1.1 200 OK"37```3839Trace output:4041```console42$ HTTPX_LOG_LEVEL=trace python test_script.py43TRACE [2019-11-06 19:18:56] httpx.dispatch.connection_pool - acquire_connection origin=Origin(scheme='https' host='google.com' port=443)44TRACE [2019-11-06 19:18:56] httpx.dispatch.connection_pool - new_connection connection=HTTPConnection(origin=Origin(scheme='https' host='google.com' port=443))45TRACE [2019-11-06 19:18:56] httpx.config - load_ssl_context verify=True cert=None trust_env=True http_versions=HTTPVersionConfig(['HTTP/1.1', 'HTTP/2'])46TRACE [2019-11-06 19:18:56] httpx.config - load_verify_locations cafile=/Users/florimond/Developer/python-projects/httpx/venv/lib/python3.8/site-packages/certifi/cacert.pem

TimeoutConfig -> Timeout (#591)Tom Christiebefore adoptionc033ed1

line 47why, one step back
47TRACE [2019-11-06 19:18:56] httpx.dispatch.connection - start_connect host='google.com' port=443 timeout=Timeout(timeout=5.0)

Add DEBUG logs of HTTP requests (#502)Florimond Mancabefore adoption08069e9

lines 48–59why, one step back
48TRACE [2019-11-06 19:18:56] httpx.dispatch.connection - connected http_version='HTTP/2'
49TRACE [2019-11-06 19:18:56] httpx.dispatch.http2 - send_headers stream_id=1 method='GET' target='/' headers=[(b':method', b'GET'), (b':authority', b'google.com'), (b':scheme', b'https'), (b':path', b'/'), (b'user-agent', b'python-httpx/0.7.6'), (b'accept', b'*/*'), (b'accept-encoding', b'gzip, deflate, br'), (b'connection', b'keep-alive')]50TRACE [2019-11-06 19:18:56] httpx.dispatch.http2 - end_stream stream_id=151TRACE [2019-11-06 19:18:56] httpx.dispatch.http2 - receive_event stream_id=0 event=<RemoteSettingsChanged changed_settings:{ChangedSetting(setting=SettingCodes.MAX_CONCURRENT_STREAMS, original_value=None, new_value=100), ChangedSetting(setting=SettingCodes.INITIAL_WINDOW_SIZE, original_value=65535, new_value=1048576), ChangedSetting(setting=SettingCodes.MAX_HEADER_LIST_SIZE, original_value=None, new_value=16384)}>52TRACE [2019-11-06 19:18:56] httpx.dispatch.http2 - receive_event stream_id=0 event=<WindowUpdated stream_id:0, delta:983041>53TRACE [2019-11-06 19:18:56] httpx.dispatch.http2 - receive_event stream_id=0 event=<SettingsAcknowledged changed_settings:{}>54TRACE [2019-11-06 19:18:56] httpx.dispatch.http2 - receive_event stream_id=1 event=<ResponseReceived stream_id:1, headers:[(b':status', b'301'), (b'location', b'https://www.google.com/'), (b'content-type', b'text/html; charset=UTF-8'), (b'date', b'Wed, 06 Nov 2019 18:18:56 GMT'), (b'expires', b'Fri, 06 Dec 2019 18:18:56 GMT'), (b'cache-control', b'public, max-age=2592000'), (b'server', b'gws'), (b'content-length', b'220'), (b'x-xss-protection', b'0'), (b'x-frame-options', b'SAMEORIGIN'), (b'alt-svc', b'quic=":443"; ma=2592000; v="46,43",h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000')]>55DEBUG [2019-11-06 19:18:56] httpx.client - HTTP Request: GET https://google.com "HTTP/2 301 Moved Permanently"56TRACE [2019-11-06 19:18:56] httpx.dispatch.connection_pool - acquire_connection origin=Origin(scheme='https' host='www.google.com' port=443)57TRACE [2019-11-06 19:18:56] httpx.dispatch.connection_pool - new_connection connection=HTTPConnection(origin=Origin(scheme='https' host='www.google.com' port=443))58TRACE [2019-11-06 19:18:56] httpx.config - load_ssl_context verify=True cert=None trust_env=True http_versions=HTTPVersionConfig(['HTTP/1.1', 'HTTP/2'])59TRACE [2019-11-06 19:18:56] httpx.config - load_verify_locations cafile=/Users/florimond/Developer/python-projects/httpx/venv/lib/python3.8/site-packages/certifi/cacert.pem

TimeoutConfig -> Timeout (#591)Tom Christiebefore adoptionc033ed1

line 60why, one step back
60TRACE [2019-11-06 19:18:56] httpx.dispatch.connection - start_connect host='www.google.com' port=443 timeout=Timeout(timeout=5.0)

Add DEBUG logs of HTTP requests (#502)Florimond Mancabefore adoption08069e9

lines 61–74why, one step back
61TRACE [2019-11-06 19:18:56] httpx.dispatch.connection - connected http_version='HTTP/2'
62TRACE [2019-11-06 19:18:56] httpx.dispatch.http2 - send_headers stream_id=1 method='GET' target='/' headers=[(b':method', b'GET'), (b':authority', b'www.google.com'), (b':scheme', b'https'), (b':path', b'/'), (b'user-agent', b'python-httpx/0.7.6'), (b'accept', b'*/*'), (b'accept-encoding', b'gzip, deflate, br'), (b'connection', b'keep-alive')]63TRACE [2019-11-06 19:18:56] httpx.dispatch.http2 - end_stream stream_id=164TRACE [2019-11-06 19:18:56] httpx.dispatch.http2 - receive_event stream_id=0 event=<RemoteSettingsChanged changed_settings:{ChangedSetting(setting=SettingCodes.MAX_CONCURRENT_STREAMS, original_value=None, new_value=100), ChangedSetting(setting=SettingCodes.INITIAL_WINDOW_SIZE, original_value=65535, new_value=1048576), ChangedSetting(setting=SettingCodes.MAX_HEADER_LIST_SIZE, original_value=None, new_value=16384)}>65TRACE [2019-11-06 19:18:56] httpx.dispatch.http2 - receive_event stream_id=0 event=<WindowUpdated stream_id:0, delta:983041>66TRACE [2019-11-06 19:18:56] httpx.dispatch.http2 - receive_event stream_id=0 event=<SettingsAcknowledged changed_settings:{}>67TRACE [2019-11-06 19:18:56] httpx.dispatch.http2 - receive_event stream_id=1 event=<ResponseReceived stream_id:1, headers:[(b':status', b'200'), (b'date', b'Wed, 06 Nov 2019 18:18:56 GMT'), (b'expires', b'-1'), (b'cache-control', b'private, max-age=0'), (b'content-type', b'text/html; charset=ISO-8859-1'), (b'p3p', b'CP="This is not a P3P policy! See g.co/p3phelp for more info."'), (b'content-encoding', b'gzip'), (b'server', b'gws'), (b'content-length', b'5073'), (b'x-xss-protection', b'0'), (b'x-frame-options', b'SAMEORIGIN'), (b'set-cookie', b'1P_JAR=2019-11-06-18; expires=Fri, 06-Dec-2019 18:18:56 GMT; path=/; domain=.google.com; SameSite=none'), (b'set-cookie', b'NID=190=m8G9qLxCz2_4HbZI02ON2HTJF4xTvOhoJiS57Hm-OJrNS2eY20LfXMR_u-mLjujeshW5-BTezI69OGpHksT4ZK2TCDsWeU0DF7AmDTjjXFOdj30eIUTpNq7r9aWRvI8UrqiwlIsLkE8Ee3t5PiIiVdSMUcji7dkavGlMUpkMXU8; expires=Thu, 07-May-2020 18:18:56 GMT; path=/; domain=.google.com; HttpOnly'), (b'alt-svc', b'quic=":443"; ma=2592000; v="46,43",h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000')]>68DEBUG [2019-11-06 19:18:56] httpx.client - HTTP Request: GET https://www.google.com/ "HTTP/2 200 OK"69TRACE [2019-11-06 19:18:56] httpx.dispatch.http2 - receive_event stream_id=1 event=<DataReceived stream_id:1, flow_controlled_length:5186, data:1f8b08000000000002ffc55af97adb4692ff3f4f>70TRACE [2019-11-06 19:18:56] httpx.dispatch.http2 - receive_event stream_id=1 event=<DataReceived stream_id:1, flow_controlled_length:221, data:>71TRACE [2019-11-06 19:18:56] httpx.dispatch.http2 - receive_event stream_id=1 event=<StreamEnded stream_id:1>72TRACE [2019-11-06 19:18:56] httpx.dispatch.http2 - receive_event stream_id=0 event=<PingReceived ping_data:0000000000000000>73TRACE [2019-11-06 19:18:56] httpx.dispatch.connection_pool - release_connection connection=HTTPConnection(origin=Origin(scheme='https' host='www.google.com' port=443))74TRACE [2019-11-06 19:18:56] httpx.dispatch.connection - close_connection

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 75–90why, one step back
75```
7677`SSLKEYLOGFILE`78-----------7980Valid values: a filename8182If 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.8384Support for `SSLKEYLOGFILE` requires Python 3.8 and OpenSSL 1.1.1 or newer.8586Example:8788```python89# test_script.py90import httpx

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

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

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 94–109why, one step back
94```
9596```console97SSLKEYLOGFILE=test.log python test_script.py98cat test.log99# TLS secrets log file, generated by OpenSSL / Python100SERVER_HANDSHAKE_TRAFFIC_SECRET XXXX101EXPORTER_SECRET XXXX102SERVER_TRAFFIC_SECRET_0 XXXX103CLIENT_HANDSHAKE_TRAFFIC_SECRET XXXX104CLIENT_TRAFFIC_SECRET_0 XXXX105SERVER_HANDSHAKE_TRAFFIC_SECRET XXXX106EXPORTER_SECRET XXXX107SERVER_TRAFFIC_SECRET_0 XXXX108CLIENT_HANDSHAKE_TRAFFIC_SECRET XXXX109CLIENT_TRAFFIC_SECRET_0 XXXX

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

lines 110–139why, one step back
110```
111112`SSL_CERT_FILE`113-----------114115Valid values: a filename116117if this environment variable is set then HTTPX will load118CA certificate from the specified file instead of the default119location.120121Example:122123```console124SSL_CERT_FILE=/path/to/ca-certs/ca-bundle.crt python -c "import httpx; httpx.get('https://example.com')"125```126127`SSL_CERT_DIR`128-----------129130Valid values: a directory131132if this environment variable is set then HTTPX will load133CA certificates from the specified location instead of the default134location.135136Example:137138```console139SSL_CERT_DIR=/path/to/ca-certs/ python -c "import httpx; httpx.get('https://example.com')"

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

line 140why, one step back
140```

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

lines 141–154why, one step back
141
142`HTTP_PROXY`, `HTTPS_PROXY`, `ALL_PROXY`143----------------------------------------144145Valid values: A URL to a proxy146147Sets the proxy to be used for `http`, `https`, or all requests respectively.148149```bash150export HTTP_PROXY=http://127.0.0.1:3080151152# This request will be sent through the proxy153python -c "import httpx; httpx.get('http://example.com')"154```