Closed zxdavb closed 4 years ago
Without the fix, we have:
(venv) dbonnes@vm-builder:~/clients/evohome-client$ git checkout master
...
(venv) dbonnes@vm-builder:~/clients/evohome-client$ python
Python 3.7.5rc1 (default, Oct 8 2019, 16:47:45)
[GCC 9.2.1 20191008] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import evohomeclient2
>>> from datetime import datetime as dt
>>>
>>> access_token = "vHzIs8HvIGB ...
>>> access_token_expires = "2019-10-12 13:49:51"
>>>
>>> username = "REDACTED"
>>> password = "REDACTED"
>>>
>>> client = evohomeclient2.EvohomeClient(
... username,
... password,
... access_token=f"{access_token}AA",
... access_token_expires=dt.strptime(access_token_expires, "%Y-%m-%d %H:%M:%S"),
... )
Traceback (most recent call last):
File "<stdin>", line 5, in <module>
File "/home/dbonnes/clients/evohome-client/evohomeclient2/__init__.py", line 78, in __init__
self._login()
File "/home/dbonnes/clients/evohome-client/evohomeclient2/__init__.py", line 81, in _login
self.user_account()
File "/home/dbonnes/clients/evohome-client/evohomeclient2/__init__.py", line 199, in user_account
response.raise_for_status()
File "/home/dbonnes/clients/evohome-client/venv/lib/python3.7/site-packages/requests/models.py", line 940, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://tccna.honeywell.com/WebAPI/emea/api/v1/userAccount
>>>
With the fix, we have (note the WARNING
):
(venv) dbonnes@vm-builder:~/clients/evohome-client$ python
Python 3.7.5rc1 (default, Oct 8 2019, 16:47:45)
[GCC 9.2.1 20191008] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import evohomeclient2
>>> from datetime import datetime as dt
>>>
>>> access_token = "vHzIs8HvIGB ...
>>> access_token_expires = "2019-10-12 13:49:51"
>>>
>>> username = "REDACTED"
>>> password = "REDACTED"
>>>
>>> client = evohomeclient2.EvohomeClient(
... username,
... password,
... access_token=f"{access_token}AA",
... access_token_expires=dt.strptime(access_token_expires, "%Y-%m-%d %H:%M:%S"),
... )
WARNING:evohomeclient2:Unauthorized access_token (will try re-authenticating).
>>>
>>> client.installation()
[{'locationInfo': {'locationId': ...
>>>
Thanks @watchforstock - will you tag this as 0.3.4?
@zxdavb Indeed, now at https://pypi.org/project/evohomeclient/0.3.4/
Under certain circumstances, 'bad' (albeit valid) access tokens will be presented to the library, and the consequent failure will not be handled appropriately.
Either the
access_token
is 'bad', or it was 'good', but is now expired with a 'bad'access_token_expires
.These 'certain' circumstances may be contrived, but I have seen this error with users of Home Assistant.
Specifically (note the corrupted access token):
Will cause (note this is from the async version of evohome-client, but the issue is the same):
This is a proposed solution.