Merge pull request #5670 from smarie/pr_proxy_conf_helper_and_doc
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Proxy related doc updates
authored by Ian Stapleton Cordasco · committed by GitHub · parents 589c454, f02a80c · Browse files · 2 files·+47 added−5 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+47 added−5 removed
- other:+47 added−5 removed
Provenance
- Commit
5035827- Tree
d813af1- Author
Ian Stapleton Cordasco <graffatcolmingov@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
589c454- Parent 2
f02a80c
2 files changed+47 added−5 removed
modified:docs/user/advanced.rst+46 added-5 removed
587 unmodified lines588 }589 590 requests.get('http://example.org', proxies=proxies)591 592-You can also configure proxies by setting the environment variables593-``HTTP_PROXY`` and ``HTTPS_PROXY``.592+Alternatively you can configure it once for an entire593+:class:`Session <requests.Session>`::594 595-::595+ import requests596 597+ proxies = {598+ 'http': 'http://10.10.1.10:3128',599+ 'https': 'http://10.10.1.10:1080',600+ }601+ session = request.Session()602+ session.proxies.update(proxies)603+604+ session.get('http://example.org')605+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+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 604-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 606- 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 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+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 linesmodified:AUTHORS.rst+1 added
188 unmodified lines189 - Rajiv Mayani (`@mayani <https://github.com/mayani>`_)190 - Antti Kaihola (`@akaihola <https://github.com/akaihola>`_)191 - "Dull Bananas" <dull.bananas0@gmail.com> (`@dullbananas <https://github.com/dullbananas>`_)192 - Alessio Izzo (`@aless10 <https://github.com/aless10>`_)193+- Sylvain Marié (`@smarie <https://github.com/smarie>`_)