1313
1414import requests
1515from . import upwork
16+ from requests .adapters import HTTPAdapter
17+ from requests .packages .urllib3 .util .retry import Retry
1618from requests_oauthlib import OAuth1 # type: ignore
1719from urllib .parse import parse_qsl , urlencode
1820
@@ -36,6 +38,9 @@ class Client(object):
3638 def __init__ (self , config ):
3739 self .config = config
3840
41+ self .requests = requests .Session ()
42+ self .requests .mount ('https://' , HTTPAdapter (max_retries = Retry (total = 0 )))
43+
3944 def get_request_token (self ):
4045 """Get request token"""
4146 oauth = OAuth1 (self .config .consumer_key , self .config .consumer_secret )
@@ -165,13 +170,13 @@ def send_request(self, uri, method="get", params={}):
165170 url = full_url (get_uri_with_format (uri , self .epoint ), self .epoint )
166171
167172 if method == "get" :
168- r = requests .get (url , params = params , auth = oauth , verify = self .config .verify_ssl )
173+ r = self . requests .get (url , params = params , auth = oauth , verify = self .config .verify_ssl )
169174 elif method == "put" :
170175 headers = {"Content-type" : "application/json" }
171- r = requests .put (url , json = params , headers = headers , auth = oauth , verify = self .config .verify_ssl )
176+ r = self . requests .put (url , json = params , headers = headers , auth = oauth , verify = self .config .verify_ssl )
172177 elif method in {"post" , "delete" }:
173178 headers = {"Content-type" : "application/json" }
174- r = requests .post (url , json = params , headers = headers , auth = oauth , verify = self .config .verify_ssl )
179+ r = self . requests .post (url , json = params , headers = headers , auth = oauth , verify = self .config .verify_ssl )
175180 else :
176181 raise ValueError (
177182 'Do not know how to handle http method "{0}"' .format (method )
0 commit comments