jekirl/poketrainer

Indent typo in _heartbeat

rirze opened this issue · 3 comments

rirze commented

Lines 266-276 are indented an extra tab, causing an error AttributeError: 'bool' object has no attribute 'get'. The lines relevant are shown below:

        # making a standard call to update position, etc
        req = self.api.create_request()
        req.get_player()
        if self._heartbeat_number % 10 == 0:
            req.check_awarded_badges()
            req.get_inventory()
        res = req.call()
        if not res or res.get("direction", -1) == 102:
            self.log.error("There were a problem responses for api call: %s. Restarting!!!", res)
            self.api.force_refresh_access_token()
            raise AuthException("Token probably expired?")

Unindenting these lines fixes this error.

you should not unindent those lines, they are meant to be only executed when no resource is passed to the _heartbeat

would need some more information about the error you got, since i've never seen that occur

rirze commented

In the original code, there is a call on line 177 self._heartbeat(login, True) where login ends up being a bool. When I debugged the code, it was passed in as _heartbeat(res=True, login_response=True). So if res ends up not being None, it bypasses the create_request call and attempts to get the responses attribute from the bool res.

def _heartbeat(self, res=None, login_response=False):
        if res is None:
            # limit the amount of heartbeats, every second is just too much in my opinion!
            if (not self._heartbeat_number % self._heartbeat_frequency == 0 and
                    not self._heartbeat_number % self._full_heartbeat_frequency == 0):
                self._heartbeat_number += 1
                return

            # making a standard call to update position, etc
            req = self.api.create_request()
            req.get_player()
            if self._heartbeat_number % 10 == 0:
                req.check_awarded_badges()
                req.get_inventory()
            res = req.call()
            if not res or res.get("direction", -1) == 102:
                self.log.error("There were a problem responses for api call: %s. Restarting!!!", res)
                self.api.force_refresh_access_token()
                raise AuthException("Token probably expired?")

        self.log.debug(
            'Response dictionary: \n\r{}'.format(json.dumps(res, indent=2, default=lambda obj: obj.decode('utf8'))))

        responses = res.get('responses', {})

ok i see the issue, though indenting does not fix the issue.

login is only fals if for some reason the login has failed, i just merged a fix to mitigate this, thanks for pointing it out

will close now, just write again if it is not resolved for some reason