def auth_api_request(self, api_endpoint, method='GET', input_dict=None):
        '''Send API request to DEP or depsim providing OAuth where necessary.

        We implement the logic of attempting OAuth1 authentication here. We
        could have tried to implement recursive calling of `api_request()` but
        to avoid potential infinite loops and to more granularly control the
        flow we opted to manually code the error cases and retries here.
        '''

        # if we have no auth/session token, then try to get one
        if not self.session_token:
            self.oauth1()

        try:
            return self.api_request(api_endpoint, method, input_dict)
        except __HOLE__, e:
            response = e.read().strip("\"\n\r")
            response_l = response.lower()

            if e.code == 403 and response_l == 'forbidden':
                # authentication token is invalid
                # try to get a new one
                self.oauth1()

                # try the request a second time
                return self.api_request(api_endpoint, method, input_dict)

            if e.code == 401 and response_l == 'unauthorized':
                # authentication token has expired
                # try to get a new one
                self.oauth1()

                # try the request a second time
                return self.api_request(api_endpoint, method, input_dict)

            if e.code == 400:
                raise DEP400Error(response, e)

            raise
dataset/ETHPy150Open jessepeterson/commandment/commandment/utils/dep.py/DEP.auth_api_request