Tesla.authorized is inherited unchanged from requests_oauthlib.OAuth2Session:
@property
def authorized(self):
return bool(self.access_token)
This only tells you a token exists in the cache, not that it's still valid, so once
cache.json holds any token, even one whose refresh_token has expired, authorized still returns
True, fetch_token()/api() skip the interactive flow, and the first API call
instead falls into automatic token refresh, which fails with
oauthlib.oauth2.rfc6749.errors.LoginRequired: (login_required) The refresh_token is invalid.
My workaround is to force-clear state first:
tesla.token = {}
del tesla.access_token
tesla.fetch_token()
Feels like .authorized should do some kind of a check on this front, but doesn't feel like it would be lightweight.
Not sure what to suggest, but wanted to log it in case others encounter it.
Tesla.authorizedis inherited unchanged fromrequests_oauthlib.OAuth2Session:This only tells you a token exists in the cache, not that it's still valid, so once
cache.jsonholds any token, even one whoserefresh_tokenhas expired,authorizedstill returnsTrue,fetch_token()/api()skip the interactive flow, and the first API callinstead falls into automatic token refresh, which fails with
oauthlib.oauth2.rfc6749.errors.LoginRequired: (login_required) The refresh_token is invalid.My workaround is to force-clear state first:
Feels like
.authorizedshould do some kind of a check on this front, but doesn't feel like it would be lightweight.Not sure what to suggest, but wanted to log it in case others encounter it.