herrersystem / fbxtools

Interface within Freebox API and Python
GNU General Public License v3.0
13 stars 5 forks source link

get_app_token : la demande reste 'pending' puis 'timeout' #1

Closed afer92 closed 7 years ago

afer92 commented 7 years ago

Pour valider la demande POST /api/v3/login/authorize/ doit être validée par une série de GET /api/v3/login/authorize/{track_id} jusqu'à ce que le status soit 'granted' : http://dev.freebox.fr/sdk/os/login/#track-authorization-progress Proposition de code : def get_app_token(self): """ Allow and register your app to the Freebox Server. """ infos = parse_infos_file(self.app_infos) response = self.init_app(infos)['data']

    if response['success']:
        with open(self.app_auth, 'w') as f:
            content = json.dumps(response['result'])
            track_id = response['result']['track_id']
            f.write(content)

            if not self.mute:
                print('%s file was generated.' % self.app_auth)
                print('Press ">" button on the dial of the Freebox')

            **# boucle pour attendre granted
            status = "pending"
            count = 0
            while (status!="granted") and (count<20):
                count += 1
                response1 = self.get_status(track_id)['data']
                print (response1)
                if response['success']:
                    status = response1['result']['status']
                time.sleep(2)**

    else:
        raise FbxAppToken(
            response['data']['error_code'],
            response['data']['error_code']
        )

    return (
        response['result']['app_token'],
        response['result']['track_id']
    )