florianbeer/grafana-netatmo

OAuth2 Token stopped working at midnight 2023-12-04

Closed this issue · 4 comments

baiti commented

I haven't touched a thing in months. All worked until mitnight last night, now here is what I get:

code=400, reason=, body=b'{"error":"invalid_grant"}'
Traceback (most recent call last):
  File "/home/xxx/new_netatmo/./netatmo_influx.py", line 25, in <module>
    weatherData = lnetatmo.WeatherStationData(authorization)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xxx/new_netatmo/lnetatmo.py", line 282, in __init__
    self.getAuthToken = authData.accessToken
                        ^^^^^^^^^^^^^^^^^^^^
  File "/home/xxx/new_netatmo/lnetatmo.py", line 181, in accessToken
    if self.expiration < time.time() : self.renew_token()
                                       ^^^^^^^^^^^^^^^^^^
  File "/home/xxx/new_netatmo/lnetatmo.py", line 192, in renew_token
    if self.refreshToken != resp['refresh_token']:
                            ~~~~^^^^^^^^^^^^^^^^^
TypeError: 'NoneType' object is not subscriptable

Has anything changed on netatmos side?

baiti commented

Update: Turns out, the refresh_token was expired. It is typically valid for 1 year. When an access_token is refreshed and the refresh_token reaches expiration date, the caller typically also gets a new refresh token but netatmo_influx.py uses a hardcoded refresh_token so no surprise it stops working after a year, requiring a manual refresh. At least that is, what I believe, has happened.

rvk01 commented

... the caller typically also gets a new refresh token but netatmo_influx.py uses a hardcoded refresh_token so no surprise it stops working after a year, requiring a manual refresh.

You will find out that netatmo changed this recently and the refresh token gets renewed each time you get a new access token !!

Ps. There is a new version of lnetatmo which fixes this.
See discussion here
philippelt/netatmo-api-python#73

baiti commented

Thx for the pointer!

Upgrading to version 4.0.0 of lnetatmo (pip3 install --upgrade lnetatmo) and my last commit should get everything back in a working order.