vangorra / python_withings_api

Library for the Withings Health API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question about token refreshing

Hansesto opened this issue · comments

Hello,

We are using the API in this repository, seems awesome.

However, we are experiencing issues on token refreshing, and the token fails to be refreshed. Currently we are using the api in 30 minute intervals, by pulling data from Withings. The token causes issues and we receive the following error: Failed to get measurements from Withings, aborting. Exception: (missing_token) Missing access token parameter. (The part before the "Exception" is our own debugging information.

When this occurs, we also try to manually refresh the token, using the api.refresh_token() method, but the same error comes up: Failed to manually refresh the token. Exception: (missing_token) Missing access token parameter..

We however do have the access token parameter, because for a while the pull works without issues. It is only after some days, that the flow breaks for some reason.

When trying to figure out what is wrong, I noticed that in the __init__.py is the following:

        self._client: Final = OAuth2Session(
            credentials.client_id,
            token=token,
            client=WebApplicationClient(  # nosec
                credentials.client_id, token=token, default_token_placement="query"
            ),
            auto_refresh_url="%s/%s" % (WithingsAuth.URL, WithingsAuth.PATH_TOKEN),
            auto_refresh_kwargs={
                "client_id": credentials.client_id,https://guides.github.com/features/mastering-markdown/
                "client_secret": credentials.consumer_secret,
            },
            token_updater=self._update_token,

In which the keyword arguments client_id and client_secret are set, and some parameters are handled by the OAuth library. But in the Withings API, they also mention: action which should take the constant value of requesttoken. This seems new, since I don't remember seeing this before in the Withings API documentation.

Could it be that because of that, the token refresh fails sometimes?

If not, do you have some suggestions on how we should proceed on solving this inconsistent operation.

Best regards,
Hannes Järvinen

Thanks for finding this. New version created. 2.1.9
This a newer addition to the api spec. It's not the first time Withings made breaking changes to the API.