mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
A utility function to fetch environment proxies
This adds support for lowercase environment proxy variables (which are quite popular too). It returns proxies in a format compatible with request's proxy parameter. Moreover, it can be used in the request models for proxy defaults. Signed-off-by: Rohan Jain <crodjer@gmail.com>
This commit is contained in:
@@ -446,3 +446,19 @@ def requote_uri(uri):
|
||||
# Then quote only illegal characters (do not quote reserved, unreserved,
|
||||
# or '%')
|
||||
return quote(unquote_unreserved(uri), safe="!#$%&'()*+,/:;=?@[]~")
|
||||
|
||||
def get_environ_proxies():
|
||||
"""Return a dict of environment proxies."""
|
||||
|
||||
proxy_keys = [
|
||||
'all',
|
||||
'http',
|
||||
'https',
|
||||
'ftp',
|
||||
'socks',
|
||||
'no'
|
||||
]
|
||||
|
||||
get_proxy = lambda k: os.environ.get(k) or os.environ.get(k.upper())
|
||||
proxies = [(key, get_proxy(key + '_proxy')) for key in proxy_keys]
|
||||
return dict([(key, val) for (key, val) in proxies if val])
|
||||
|
||||
Reference in New Issue
Block a user