Skip to content

[Bug] Refresh token rejected (2002) causes a retry loop every ~3 s and gets the home IP rate-limited (429) at login #999

In review
SecKatie/wyzeapy
#407

Description

@Arch0n007

Describe the bug
While Home Assistant was running, Wyze started rejecting the stored refresh token with code 2002 ("refresh token is error"). wyzeapy raises this as UnknownApiError, not AccessTokenError, so the integration never started reauth. Instead, every device's update loop in wyzeapy.services.update_manager called refresh_if_should() → refresh() again on its next cycle. That produced about 17,500 failed refresh attempts in 16 hours (roughly one every 3 seconds across all devices), and all Wyze entities stopped responding.

After a restart, the integration could not log in again with the saved username/password: auth-prod.api.wyze.com/api/user/login answered HTTP 429 for every login from our IP, including a test request with made-up credentials (X-RateLimit-Remaining: 0). api.wyzecam.com still answered normally. The block lifted by itself a few hours later. After that, setup with the saved credentials and API key worked straight away, so the API key had not been revoked.

PR #998 maps 2002 to ConfigEntryAuthFailed in async_setup_entry, which covers startup. It does not cover the case above, where the token goes bad while the integration is already running and the update loop keeps retrying it.

To Reproduce

  1. Integration is set up and running normally.
  2. Wyze invalidates the refresh token server-side (here at 01:25 local time, no action on our side).
  3. Every update cycle retries refresh(), logs UnknownApiError: ('2002', 'refresh token is error'), and tries again on the next cycle.
  4. After many hours, logins from the same IP get HTTP 429.

Expected behavior
On 2002 during a refresh, stop polling and start reauth once (as token_exception_handler already does for AccessTokenError/LoginError), instead of retrying indefinitely. It would also help to back off on repeated refresh failures, and to treat a 429 at login as "retry later" rather than a setup error.

System configuration
System: Docker (Home Assistant Container)
HA Version: 2026.11.1
WyzeApi Version: v0.1.41 (wyzeapy 0.8.1)

home-assistant.log

2026-11-25 01:25:56 ERROR (MainThread) [wyzeapy.services.update_manager] Unknown error happened during updating device info
Traceback (most recent call last):
  File ".../wyzeapy/services/update_manager.py", line 59, in update
    self.device = await self.service.update(self.device)
  File ".../wyzeapy/services/camera_service.py", line 61, in update
    response = await self._get_event_list(10)
  File ".../wyzeapy/services/base_service.py", line 444, in _get_event_list
    await self._auth_lib.refresh_if_should()
  File ".../wyzeapy/wyze_auth_lib.py", line 357, in refresh_if_should
    await self.refresh()
  File ".../wyzeapy/wyze_auth_lib.py", line 387, in refresh
    check_for_errors_standard(self, response_json)
  File ".../wyzeapy/utils.py", line 143, in check_for_errors_standard
    raise UnknownApiError(response_code, response_json["msg"])
wyzeapy.exceptions.UnknownApiError: ('2002', 'refresh token is error')
(repeated about 17,500 times until 17:19)

After restart with tokens cleared:
ERROR (MainThread) [homeassistant.config_entries] Error setting up entry for wyzeapi
aiohttp.client_exceptions.ContentTypeError: 429, message='Attempt to decode JSON with unexpected mimetype: ', url='https://auth-prod.api.wyze.com/api/user/login'

Activity

  1. added
    bug
    on Nov 25, 2026
  2. Benjin commented on Nov 27, 2026

    @Benjin

    I'm also encountering this issue; looks like Wyzepy needs updating.

  3. dozer8383 commented on Nov 27, 2026

    @dozer8383

    I started getting this issue when I updated to 2026.12.0b2, but I think it may have been coincidence, since the thermostat's status and sensors weren't updating at all yesterday.

  4. CenterInYou commented on Nov 29, 2026

    @CenterInYou

    I started getting this issue when I updated to 2026.12.0b2, but I think it may have been coincidence, since the thermostat's status and sensors weren't updating at all yesterday.

    I'm thinking it was coincidence. I'm still on 2026.11 and having the same issue.

  5. locus123123 commented on Nov 30, 2026

    @locus123123

    I'm getting very similar error on 2026.11 as well...

    Traceback (most recent call last):
    File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1023, in __async_setup_with_context
    setup_result: bool | None = await component.async_setup_entry(
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    hass, self
    ^^^^^^^^^^
    ) # type: ignore[func-returns-value]
    ^
    File "/config/custom_components/wyzeapi/init.py", line 122, in async_setup_entry
    await client.login(
    ...<5 lines>...
    )
    File "/usr/local/lib/python3.14/site-packages/wyzeapy/init.py", line 112, in login
    await self._auth_lib.refresh()
    File "/usr/local/lib/python3.14/site-packages/wyzeapy/wyze_auth_lib.py", line 387, in refresh
    check_for_errors_standard(self, response_json)
    ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
    File "/usr/local/lib/python3.14/site-packages/wyzeapy/utils.py", line 143, in check_for_errors_standard
    raise UnknownApiError(response_code, response_json["msg"])
    wyzeapy.exceptions.UnknownApiError: ('2002', 'refresh token is error')

  6. gilbertth commented on Nov 30, 2026

    @gilbertth

    Same issue wyze integration not working anymore

  7. mullethunter324 commented on Dec 1, 2026

    @mullethunter324

    I am have the same issue, but my lighting automations are still working, just mainly the switches that aren't working for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions