Skip to content
Myr

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

2 files+47 added−5 removed

modified:docs/user/advanced.rst+46 added-5 removed
587 unmodified lines
588 }589590 requests.get('http://example.org', proxies=proxies)591592You can also configure proxies by setting the environment variables593``HTTP_PROXY`` and ``HTTPS_PROXY``.592Alternatively you can configure it once for an entire593:class:`Session <requests.Session>`::594595::595 import requests596597 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)603604 session.get('http://example.org')605606When the proxies configuration is not overridden in python as shown above,607by default Requests relies on the proxy configuration defined by standard608environment variables ``http_proxy``, ``https_proxy``, ``no_proxy`` and609``curl_ca_bundle``. Uppercase variants of these variables are also supported.610You can therefore set them to configure Requests (only set the ones relevant611to your needs)::612613 $ export HTTP_PROXY="http://10.10.1.10:3128"614 $ export HTTPS_PROXY="http://10.10.1.10:1080"615616 $ python617 >>> import requests618 >>> requests.get('http://example.org')619604To use HTTP Basic Auth with your proxy, use the `http://user:password@host/` syntax::620To use HTTP Basic Auth with your proxy, use the `http://user:password@host/`621syntax in any of the above configuration entries::622606 proxies = {'http': 'http://user:pass@10.10.1.10:3128/'}623 $ export HTTPS_PROXY="http://user:pass@10.10.1.10:1080"624625 $ python626 >>> proxies = {'http': 'http://user:pass@10.10.1.10:3128/'}627628.. warning:: Storing sensitive username and password information in an629 environment variable or a version-controled file is a security risk and is630 highly discouraged.631632To give a proxy for a specific scheme and host, use the633`scheme://hostname` form for the key. This will match for634any request to the given scheme and exact hostname.635
2 unmodified lines
638 proxies = {'http://10.20.1.128': 'http://10.10.1.10:5323'}639640Note that proxy URLs must include the scheme.641642Finally, note that using a proxy for https connections typically requires your643local machine to trust the proxy's root certificate. By default the list of644certificates trusted by Requests can be found with::645646 from requests.utils import DEFAULT_CA_BUNDLE_PATH647 print(DEFAULT_CA_BUNDLE_PATH)648649You override this default certificate bundle by setting the standard650``curl_ca_bundle`` environment variable to another file path::651652 $ export curl_ca_bundle="/usr/local/myproxy_info/cacert.pem"653 $ export https_proxy="http://10.10.1.10:1080"654655 $ python656 >>> import requests657 >>> requests.get('https://example.org')658659SOCKS660^^^^^661662.. versionadded:: 2.10.0
416 unmodified lines
modified:AUTHORS.rst+1 added
188 unmodified lines
189- 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>`_)