@@ -99,7 +99,8 @@ class RestSession(object):
9999
100100 def __init__ (self , access_token , base_url ,
101101 single_request_timeout = DEFAULT_SINGLE_REQUEST_TIMEOUT ,
102- wait_on_rate_limit = DEFAULT_WAIT_ON_RATE_LIMIT ):
102+ wait_on_rate_limit = DEFAULT_WAIT_ON_RATE_LIMIT ,
103+ proxy_dict = None ):
103104 """Initialize a new RestSession object.
104105
105106 Args:
@@ -111,6 +112,8 @@ def __init__(self, access_token, base_url,
111112 HTTP REST API request.
112113 wait_on_rate_limit(bool): Enable or disable automatic rate-limit
113114 handling.
115+ proxy_dict(dict): Dictionary of proxies passed on to the requests
116+ session.
114117
115118 Raises:
116119 TypeError: If the parameter types are incorrect.
@@ -120,6 +123,7 @@ def __init__(self, access_token, base_url,
120123 check_type (base_url , basestring , may_be_none = False )
121124 check_type (single_request_timeout , int )
122125 check_type (wait_on_rate_limit , bool , may_be_none = False )
126+ check_type (proxy_dict , dict , may_be_none = True )
123127
124128 super (RestSession , self ).__init__ ()
125129
@@ -132,6 +136,9 @@ def __init__(self, access_token, base_url,
132136 # Initialize a new `requests` session
133137 self ._req_session = requests .session ()
134138
139+ if proxy_dict is not None :
140+ self ._req_session .proxies .update (proxy_dict )
141+
135142 # Update the headers of the `requests` session
136143 self .update_headers ({'Authorization' : 'Bearer ' + access_token ,
137144 'Content-type' : 'application/json;charset=utf-8' })
0 commit comments