tillsteinbach / VWsFriend

VW WeConnect visualization and control
MIT License
248 stars 19 forks source link

No new data in dashboard - token_expired #563

Open oldgitdaddy opened 1 year ago

oldgitdaddy commented 1 year ago

Hello, The dashboard did not receive any new data since 2023-10-11 08:46:43. I suspect there is an update in the API, as there also has been an update in the app, which required logging in again. The dashboard version is 0.23.10

Hints are kindly appreciated.

Please find the logs below:

2023-10-11T06:55:00+0000:ERROR:openid_session:Retrieval Error while refreshing token. Probably the token was invalidated. Trying to do a new                                                                                                                                                                                                                                                                                                                                                  login instead.
Traceback (most recent call last):
  File "/opt/venv/lib/python3.11/site-packages/weconnect/auth/openid_session.py", line 192, in request
    url, headers, data = self.addToken(url, body=data, headers=headers, access_type=access_type, token=token)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.11/site-packages/weconnect/auth/openid_session.py", line 240, in addToken
    raise TokenExpiredError()
oauthlib.oauth2.rfc6749.errors.TokenExpiredError: (token_expired)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/venv/lib/python3.11/site-packages/weconnect/auth/openid_session.py", line 198, in request
    self.refresh()
  File "/opt/venv/lib/python3.11/site-packages/weconnect/auth/we_connect_session.py", line 82, in refresh
    self.refreshTokens(
  File "/opt/venv/lib/python3.11/site-packages/weconnect/auth/we_connect_session.py", line 361, in refreshTokens
    raise RetrievalError(f'Status Code from WeConnect while refreshing tokens was: {tokenResponse.status_code}')
weconnect.errors.RetrievalError: Status Code from WeConnect while refreshing tokens was: 403

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/venv/bin/vwsfriend", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/opt/venv/lib/python3.11/site-packages/vwsfriend/vwsfriend_base.py", line 517, in main
    weConnect.update(updateCapabilities=True, updatePictures=True, force=True)
  File "/opt/venv/lib/python3.11/site-packages/weconnect/weconnect.py", line 193, in update
    self.updateVehicles(updateCapabilities=updateCapabilities, updatePictures=updatePictures, force=force, selective=selective)
  File "/opt/venv/lib/python3.11/site-packages/weconnect/weconnect.py", line 218, in updateVehicles
    self.__vehicles[vin].update(fromDict=vehicleDict, updateCapabilities=updateCapabilities, updatePictures=updatePictures,
  File "/opt/venv/lib/python3.11/site-packages/weconnect/elements/vehicle.py", line 220, in update
    self.updateStatus(updateCapabilities=updateCapabilities, force=force, selective=selective)
  File "/opt/venv/lib/python3.11/site-packages/weconnect/elements/vehicle.py", line 324, in updateStatus
    data: Optional[Dict[str, Any]] = self.weConnect.fetchData(url, force)
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.11/site-packages/weconnect/weconnect.py", line 367, in fetchData
    statusResponse: requests.Response = self.session.get(url, allow_redirects=False)
                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.11/site-packages/requests/sessions.py", line 600, in get
    return self.request("GET", url, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.11/site-packages/weconnect/auth/we_connect_session.py", line 69, in request
    return super(WeConnectSession, self).request(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.11/site-packages/weconnect/auth/openid_session.py", line 207, in request
    self.login()
  File "/opt/venv/lib/python3.11/site-packages/weconnect/auth/we_connect_session.py", line 75, in login
    authorizationUrl = self.authorizationUrl(url='https://identity.vwgroup.io/oidc/v1/authorize')
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.11/site-packages/weconnect/auth/we_connect_session.py", line 96, in authorizationUrl
    redirect = tryLoginResponse.headers['Location']
               ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
  File "/opt/venv/lib/python3.11/site-packages/requests/structures.py", line 52, in __getitem__
    return self._store[key.lower()][1]
           ~~~~~~~~~~~^^^^^^^^^^^^^
tillsteinbach commented 1 year ago

hmmm, hard to tell from the log what happened. I would guess it can be solved with a restart.

oldgitdaddy commented 1 year ago

Best guess! Restart worked! Thanks.

oldgitdaddy commented 12 months ago

Hello again :) This problem now occured again and restarting helped. Still, I believe there should be another way of handling this. The server does not even try to recconnect and get a new token. after a while. So it literally waits until somebody restarts it. This is not very convenient. Any ideas how to fix?

oldgitdaddy commented 11 months ago

Hi @tillsteinbach, Do you have any feedback? Did anybody have a similar observation? I saw that token refresh has been a problem already some time ago. Any idea what to do? Is the only option to restart the service via cron job? Looking forward to hearing from you! Thank you 💯!

korhojoa commented 11 months ago

Hi @tillsteinbach, Do you have any feedback? Did anybody have a similar observation? I saw that token refresh has been a problem already some time ago. Any idea what to do? Is the only option to restart the service via cron job? Looking forward to hearing from you! Thank you 💯!

I have a job that restarts the vwsfriend container every day, that has kept it mostly functional, but it doesn't handle the failure, just tries to mask it.