def _request(self, method, url, params=None, files=None):
        """Common handler for all HTTP requests."""
        if not params:
            params = {}
        params['apiKey'] = self.api_key

        headers = {
            'User-Agent': self.user_agent,
            'Accept': 'application/json'
        }

        try:
            if self.debug:
                print(method + ' ' + url)
                print(params)

            response = requests.request(method=method, url=self.host + url, params=params, files=files, headers=headers,
                                        timeout=self.timeout, verify=self.verify_ssl, cert=self.cert)

            if self.debug:
                print(response.status_code)
                print(response.text)

            try:
                json_response = response.json()

                message = json_response['message']
                success = json_response['success']
                response_code = json_response['responseCode']
                data = json_response['object']

                return ThreadFixResponse(message=message, success=success, response_code=response_code, data=data)
            except ValueError:
                return ThreadFixResponse(message='JSON response could not be decoded.', success=False)
        except requests.exceptions.SSLError:
            return ThreadFixResponse(message='An SSL error occurred.', success=False)
        except requests.exceptions.ConnectionError:
            return ThreadFixResponse(message='A connection error occurred.', success=False)
        except requests.exceptions.Timeout:
            return ThreadFixResponse(message='The request timed out after ' + str(self.timeout) + ' seconds.',
                                     success=False)
        except requests.exceptions.RequestException:
            return ThreadFixResponse(message='There was an error while handling the request.', success=False)
def _request ( self , method , url , params = None , files = None ) : if not params : params = { } params [ 'apiKey' ] = self . api_key headers = { 'User-Agent' : self . user_agent , 'Accept' : 'application/json' } try : if self . debug : print ( method + ' ' + url ) print ( params ) response = requests . request ( method = method , url = self . host + url , params = params , files = files , headers = headers , timeout = self . timeout , verify = self . verify_ssl , cert = self . cert ) if self . debug : print ( response . status_code ) print ( response . text ) try : json_response = response . json ( ) message = json_response [ 'message' ] success = json_response [ 'success' ] response_code = json_response [ 'responseCode' ] data = json_response [ 'object' ] return ThreadFixResponse ( message = message , success = success , response_code = response_code , data = data ) except ValueError : return ThreadFixResponse ( message = 'JSON response could not be decoded.' , success = False ) except requests . exceptions . SSLError : return ThreadFixResponse ( message = 'An SSL error occurred.' , success = False ) except requests . exceptions . ConnectionError : return ThreadFixResponse ( message = 'A connection error occurred.' , success = False ) except requests . exceptions . Timeout : return ThreadFixResponse ( message = 'The request timed out after ' + str ( self . timeout ) + ' seconds.' , success = False ) except requests . exceptions . RequestException : return ThreadFixResponse ( message = 'There was an error while handling the request.' , success = False )
Common handler for all HTTP requests.