Updated proxies documentation
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Sylvain MARIE · committed by Sylvain MARIE · parent d1ca591 · Browse files · 1 file·+28 added−20 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+28 added−20 removed
- other:+28 added−20 removed
Provenance
- Commit
f02a80c- Tree
7aef57b- Author
Sylvain MARIE <sylvain.marie@se.com>- Committer
Sylvain MARIE <sylvain.marie@se.com>- Parent
d1ca591
1 file changed+28 added−20 removed
modified:docs/user/advanced.rst+28 added-20 removed
588 unmodified lines589 590 requests.get('http://example.org', proxies=proxies)591 592 Alternatively you can configure it once for an entire593-:class:`Session <requests.Session>`, either manually::593+:class:`Session <requests.Session>`::594 595 import requests596 597 proxies = {4 unmodified lines602 session.proxies.update(proxies)603 604 session.get('http://example.org')605 606-or with the helper method :func:`set_http_proxy <requests.Session.set_http_proxy>`::606+When the proxies configuration is not overridden in python as shown above,607+by default Requests relies on the proxy configuration defined by standard608+environment variables ``http_proxy``, ``https_proxy``, ``no_proxy`` and609+``curl_ca_bundle``. Uppercase variants of these variables are also supported.610+You can therefore set them to configure Requests (only set the ones relevant611+to your needs)::612 608- import requests609-610- session = request.Session()611- session.set_http_proxy(http_url='http://10.10.1.10:3128', https_url='http://10.10.1.10:1080')612-613- session.get('http://example.org')614-615-You can also configure proxies by setting the environment variables616-``HTTP_PROXY``, ``HTTPS_PROXY``, ``NO_PROXY`` and ``CURL_CA_BUNDLE``.617-618-::619-613 $ export HTTP_PROXY="http://10.10.1.10:3128"614 $ export HTTPS_PROXY="http://10.10.1.10:1080"615 616 $ python617 >>> import requests618 >>> requests.get('http://example.org')619 627-To use HTTP Basic Auth with your proxy, use the `http://user:password@host/` syntax::620+To use HTTP Basic Auth with your proxy, use the `http://user:password@host/`621+syntax in any of the above configuration entries::622 629- proxies = {'http': 'http://user:pass@10.10.1.10:3128/'}623+ $ export HTTPS_PROXY="http://user:pass@10.10.1.10:1080"624 625+ $ python626+ >>> proxies = {'http': 'http://user:pass@10.10.1.10:3128/'}627+628+.. warning:: Storing sensitive username and password information in an629+ environment variable or a version-controled file is a security risk and is630+ highly discouraged.631+632 To give a proxy for a specific scheme and host, use the633 `scheme://hostname` form for the key. This will match for634 any request to the given scheme and exact hostname.635 2 unmodified lines638 proxies = {'http://10.20.1.128': 'http://10.10.1.10:5323'}639 640 Note that proxy URLs must include the scheme.641 641-Finally, note that using a proxy for https connections typically requires your local machine to trust the642-proxy's root certificate. By default the list of certificates trusted by Requests can be found with::642+Finally, note that using a proxy for https connections typically requires your643+local machine to trust the proxy's root certificate. By default the list of644+certificates trusted by Requests can be found with::645 646 from requests.utils import DEFAULT_CA_BUNDLE_PATH647 print(DEFAULT_CA_BUNDLE_PATH)648 647-You override this default certificate bundle by setting the standard ``CURL_CA_BUNDLE`` environment variable648-to another file path.649+You override this default certificate bundle by setting the standard650+``curl_ca_bundle`` environment variable to another file path::651 652+ $ export curl_ca_bundle="/usr/local/myproxy_info/cacert.pem"653+ $ export https_proxy="http://10.10.1.10:1080"654 655+ $ python656+ >>> import requests657+ >>> requests.get('https://example.org')658+659 SOCKS660 ^^^^^661 662 .. versionadded:: 2.10.0416 unmodified lines