shauntarves / wyze-sdk

A modern Python client for controlling Wyze devices.
The Unlicense
307 stars 50 forks source link

Token refresh failing as of July 15, 2024 #183

Open dwaynez opened 2 months ago

dwaynez commented 2 months ago

Has something changed? As of today (July 15, 2024) I am getting the error message "refresh token is error." and I am unable to refresh the access token with the refresh token.

mrlt8 commented 2 months ago

Check your API key - they expire after one year and need to be generated again.

dwaynez commented 2 months ago

The key had not expired, but I generated a new one anyway. The refresh token fails immediately on use. Here is my test code. import os from wyze_sdk import Client t_email="xxxx" pswd="yyy" api="zzz" # generated 07-16-2024 09:27:12 expires 1 year keyid="aaaa" response = Client().login( email=t_email, password=pswd, key_id=keyid, api_key=api ) print(response) client = Client(token=response['access_token']) print(client.cameras.list()) client = Client(refresh_token=response['refresh_token']) resp = client.refresh_token() print("resp=",resp) print(client.cameras.list())

This results in the camera list bring printed once, but the call to client.refresh_token() causes:

   Traceback (most recent call last):

File "/home/pi/zhm/devl/testwyze.py", line 22, in resp = client.refresh_token() File "/home/pi/.local/lib/python3.9/site-packages/wyze_sdk/api/client.py", line 209, in refresh_token response = self._api_client().refresh_token(refresh_token=self._refresh_token) File "/home/pi/.local/lib/python3.9/site-packages/wyze_sdk/service/api_service.py", line 72, in refresh_token return self.api_call('/app/user/refresh_token', json=kwargs) File "/home/pi/.local/lib/python3.9/site-packages/wyze_sdk/service/api_service.py", line 66, in api_call return super().api_call(api_method, http_verb=http_verb, data=None, params=None, json=json, headers=headers, auth=None) File "/home/pi/.local/lib/python3.9/site-packages/wyze_sdk/service/base.py", line 204, in api_call return self.do_post(url=api_url, headers=headers, payload=json, params=params) File "/home/pi/.local/lib/python3.9/site-packages/wyze_sdk/service/base.py", line 132, in do_post return self._do_request(client, req) File "/home/pi/.local/lib/python3.9/site-packages/wyze_sdk/service/base.py", line 109, in _do_request raise e File "/home/pi/.local/lib/python3.9/site-packages/wyze_sdk/service/base.py", line 95, in _do_request return WyzeResponse( File "/home/pi/.local/lib/python3.9/site-packages/wyze_sdk/service/wyze_response.py", line 142, in validate raise e.WyzeApiError(message, self.data) wyze_sdk.errors.WyzeApiError: The request to the Wyze API failed. The server responded with: {'code': '2002', 'ts': 1721143802024, 'msg': 'refresh token is error.', 'data': {}, 'traceId': '136e0d8bda0016be73cb0a68d77d8c82'}

renschler commented 2 months ago

I'm noticing this as well, but it started July 5 for me

looks like we are not the only ones: https://forums.wyze.com/t/refresh-tokens-not-working/303714

mrlt8 commented 2 months ago

The code is fine.

I believe the problem is the refresh token from the developer API. It works if you use a refresh token from the oauth endpoint.

renschler commented 2 months ago

I'm using the exact same code for myself and for a friend, and my account works but his doesn't.

In both cases I use the refresh token from the developer api like @dwaynez does above

mrlt8 commented 2 months ago

@xcz011 Could you look into the refresh token from the /api/user/login endpoint?

xcz011 commented 2 months ago

@xcz011 Could you look into the refresh token from the /api/user/login endpoint?

Thanks @mrlt8, we noticed this issue as well, the plan to fix is next week. I will share update here once we fix this issue.

renschler commented 2 months ago

@xcz011 is there a simple workaround we can use in the meantime? no worries if not, I am just wondering

mrlt8 commented 1 month ago

@renschler The access token is still valid, so you could just run login when needed.

xcz011 commented 1 month ago

@mrlt8 @renschler this issue got fixed. please retry and let's know the result. Thanks

renschler commented 1 month ago

thanks @xcz011 will let you know if I run into any further issues. congrats on the new wyze 3 app launch!