Skip to content
Myr

Facilitate proxy configuration by environment variables

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Johannes Gorset · committed by Johannes Gorset · parent 2f91d8e · Browse files · 2 files+35 added−0 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+35 added−0 removed

  • other:+35 added−0 removed

2 files+35 added−0 removed

modified:docs/user/advanced.rst+27 added
289 unmodified lines
290 >>> my_config = {'verbose': sys.stderr}291 >>> requests.get('http://httpbin.org/headers', config=my_config)292 2011-08-17T03:04:23.380175 GET http://httpbin.org/headers293 <Response [200]>294295Proxies296-------297298If you need to use a proxy, you can configure individual requests with the299``proxies`` argument to any request method:300301::302303 import requests304305 proxies = {306 "http": "10.10.1.10:3128"307 "https": "10.10.1.10:1080"308 }309310 requests.get("http://example.org", proxies=proxies)311312You can also configure proxies by environment variables ``HTTP_PROXY`` and ``HTTPS_PROXY``.313314::315316 $ export HTTP_PROXY="10.10.1.10:3128"317 $ export HTTPS_PROXY="10.10.1.10:1080"318 $ python319 >>> import requests320 >>> requests.get("http://example.org")
modified:requests/models.py+8 added
100 unmodified lines
101102 # Dictionary mapping protocol to the URL of the proxy (e.g. {'http': 'foo.bar:3128'})103 self.proxies = dict(proxies or [])104105 # If no proxies are given, allow configuration by environment variables106 # HTTP_PROXY and HTTPS_PROXY.107 if not self.proxies:108 if 'HTTP_PROXY' in os.environ:109 self.proxies['http'] = os.environ['HTTP_PROXY']110 if 'HTTPS_PROXY' in os.environ:111 self.proxies['https'] = os.environ['HTTPS_PROXY']112113 self.data, self._enc_data = self._encode_params(data)114 self.params, self._enc_params = self._encode_params(params)115116 #: :class:`Response <Response>` instance, containing
690 unmodified lines