def execute_http_call(method, url, params, retry, timeout, apiKey, apiKeyPrefix): """ Executes http call using requests library Parameters ---------- method : str url : str params : dict retry : Retry timeout : tuple Returns ------- Response """ # set session session = Session() session.mount('https://', HTTPAdapter(max_retries=retry)) # Documented in HTTPAdapter session.headers = { 'Authorization': '{} {}'.format(apiKeyPrefix, apiKey), 'Content-Type': 'application/json', 'User-Agent': generate_user_agent(), } if method is "GET": response = session.get(url, params=params, timeout=timeout) elif method is "POST": response = session.post(url, json=params, timeout=timeout) else: raise NotImplementedError() return response
def session(self, base_url="http://baseserver"): """ mount it to session object any request will start using URL given by prefix base_url """ session = RequestsSession() session.mount(prefix=base_url, adapter=RequestWSGIAdapter(self)) return session
def session(self, base_url="http://testserver"): if self._session is None: session = RequestsSession() session.mount(prefix=base_url, adapter=RequestsWSGIAdapter(self)) self._session = session return self._session