def _internal_request(self, request_obj, url, method, **kwargs):
method = method.lower()<EOL>if method not in self._allowed_methods:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if method == '<STR_LIT>':<EOL><INDENT>kwargs.setdefault('<STR_LIT>', True)<EOL><DEDENT>elif method in ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>if '<STR_LIT>' not in kwargs:<EOL><INDENT>kwargs['<STR_LIT>'] = {}<EOL><DEDENT>if kwargs.get('<STR_LIT>') is not None and kwargs['<STR_LIT>'].get(<EOL>'<STR_LIT>') is None:<EOL><INDENT>kwargs['<STR_LIT>']['<STR_LIT>'] = '<STR_LIT:application/json>'<EOL><DEDENT>if '<STR_LIT:data>' in kwargs and kwargs['<STR_LIT:data>'] is not None and kwargs['<STR_LIT>'].get(<EOL>'<STR_LIT>') == '<STR_LIT:application/json>':<EOL><INDENT>kwargs['<STR_LIT:data>'] = json.dumps(kwargs['<STR_LIT:data>'])  <EOL><DEDENT><DEDENT>request_done = False<EOL>token_refreshed = False<EOL>while not request_done:<EOL><INDENT>self._check_delay()  <EOL>try:<EOL><INDENT>log.info('<STR_LIT>'.format(method.upper(), url))<EOL>log.info('<STR_LIT>'.format(kwargs))<EOL>response = request_obj.request(method, url,<EOL>**kwargs)<EOL>response.raise_for_status()  <EOL>log.info('<STR_LIT>'.format(<EOL>response.status_code, response.url))<EOL>request_done = True<EOL>return response<EOL><DEDENT>except TokenExpiredError as e:<EOL><INDENT>if not self.token_backend.token.is_long_lived:<EOL><INDENT>raise e<EOL><DEDENT>if token_refreshed:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>log.info('<STR_LIT>')<EOL>self.refresh_token()<EOL>log.info('<STR_LIT>')<EOL>token_refreshed = True<EOL><DEDENT>except (ConnectionError, ProxyError, SSLError, Timeout) as e:<EOL><INDENT>log.debug('<STR_LIT>'<EOL>'<STR_LIT>'.format(url, ('<STR_LIT>'.format(self.proxy)<EOL>if self.proxy else '<STR_LIT>')))<EOL>raise e  <EOL><DEDENT>except HTTPError as e:<EOL><INDENT>try:<EOL><INDENT>error = response.json()<EOL>error_message = error.get('<STR_LIT:error>', {}).get('<STR_LIT:message>', '<STR_LIT>')<EOL><DEDENT>except ValueError:<EOL><INDENT>error_message = '<STR_LIT>'<EOL><DEDENT>status_code = int(e.response.status_code / <NUM_LIT:100>)<EOL>if status_code == <NUM_LIT:4>:<EOL><INDENT>log.error('<STR_LIT>'.format(str(e), error_message))<EOL><DEDENT>else:<EOL><INDENT>log.debug('<STR_LIT>'.format(str(e)))<EOL><DEDENT>if self.raise_http_errors:<EOL><INDENT>if error_message:<EOL><INDENT>raise HTTPError('<STR_LIT>'.format(e.args[<NUM_LIT:0>], error_message), response=response) from None<EOL><DEDENT>else:<EOL><INDENT>raise e<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return e.response<EOL><DEDENT><DEDENT>except RequestException as e:<EOL><INDENT>log.debug('<STR_LIT>'.format(str(e)))<EOL>raise e<EOL><DEDENT><DEDENT>
Internal handling of requests. Handles Exceptions.

        :param request_obj: a requests session.
        :param str url: url to send request to
        :param str method: type of request (get/put/post/patch/delete)
        :param kwargs: extra params to send to the request api
        :return: Response of the request
        :rtype: requests.Response