Skip to content
Myr

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

1 file+28 added−20 removed

modified:docs/user/advanced.rst+28 added-20 removed
588 unmodified lines
589590 requests.get('http://example.org', proxies=proxies)591592Alternatively you can configure it once for an entire593:class:`Session <requests.Session>`, either manually::593:class:`Session <requests.Session>`::594595 import requests596597 proxies = {
4 unmodified lines
602 session.proxies.update(proxies)603604 session.get('http://example.org')605606or with the helper method :func:`set_http_proxy <requests.Session.set_http_proxy>`::606When 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)::612608 import requests609610 session = request.Session()611 session.set_http_proxy(http_url='http://10.10.1.10:3128', https_url='http://10.10.1.10:1080')612613 session.get('http://example.org')614615You can also configure proxies by setting the environment variables616``HTTP_PROXY``, ``HTTPS_PROXY``, ``NO_PROXY`` and ``CURL_CA_BUNDLE``.617618::619613 $ 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')619627To 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::622629 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.641641Finally, note that using a proxy for https connections typically requires your local machine to trust the642proxy's root certificate. By default the list of certificates trusted by Requests can be found with::642Finally, 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)648647You override this default certificate bundle by setting the standard ``CURL_CA_BUNDLE`` environment variable648to another file path.649You 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