romedtino / simple-wyze-vac

Home Assistant Custom Component for Wyze Vacuum
48 stars 8 forks source link

[BUG] 400 Client Error: Bad Request on Login #72

Open drewdah opened 11 months ago

drewdah commented 11 months ago

Describe the bug I've had this addon installed for a few months, but recently it stopped working. I tried reloading the addon and it would fail to start, so I tried to uninstall / reinstall and when I entered my wyze credentials and the key id / auth key. I got "Problems Logging in. Please verify your username and password". I checked my username/password and the API keys and they are correct, I even tried creating a new API key with Wyze to see if that solved the problem, but it did not.

To Reproduce Steps to reproduce the behavior:

  1. Install simple-wyze-vac via HACS
  2. Go to Settings -> Devices -> Add Integration and select "Simple Wyze Vac"
  3. Enter your username/password, API key id and API key auth
  4. See "Problems Logging in" error

Expected behavior I expected the integration to log me in and create my wyze vacuum entities

Screenshots login-error-screenshot

Simple Wyze Vac Version

Wyze Vacuum Firmware Version

Home Assistant Version

Additional context The following error logs were visible in Settings -> System -> Logs that might be useful

This error originated from a custom integration.

Logger: homeassistant.config_entries
Source: custom_components/simple_wyze_vac/__init__.py:52
Integration: Simple Wyze Vac (documentation)
First occurred: 1:21:18 PM (3 occurrences)
Last logged: 2:33:32 PM

Error setting up entry Simple Wyze Vac for simple_wyze_vac
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 387, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/simple_wyze_vac/__init__.py", line 52, in async_setup_entry
    client = await hass.async_add_executor_job(Client, None, None, username, password, key_id, api_key, totp)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/wyze_sdk/api/client.py", line 72, in __init__
    self.login()
  File "/usr/local/lib/python3.11/site-packages/wyze_sdk/api/client.py", line 184, in login
    response = self._auth_client().user_login(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/wyze_sdk/service/auth_service.py", line 88, in user_login
    response = self.api_call(
               ^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/wyze_sdk/service/auth_service.py", line 58, in api_call
    return super().api_call(
           ^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/wyze_sdk/service/base.py", line 347, in api_call
    return super().api_call(
           ^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/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 "/usr/local/lib/python3.11/site-packages/wyze_sdk/service/base.py", line 132, in do_post
    return self._do_request(client, req)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/wyze_sdk/service/base.py", line 106, in _do_request
    raise err
  File "/usr/local/lib/python3.11/site-packages/wyze_sdk/service/base.py", line 93, in _do_request
    response.raise_for_status()
  File "/usr/local/lib/python3.11/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://auth-prod.api.wyze.com/api/user/login
This error originated from a custom integration.

Logger: custom_components.simple_wyze_vac.config_flow
Source: custom_components/simple_wyze_vac/config_flow.py:55
Integration: Simple Wyze Vac (documentation)
First occurred: 2:36:49 PM (2 occurrences)
Last logged: 2:54:39 PM

Failed to login Wyze servers.
romedtino commented 11 months ago

Have you tried logging in again? I've seen this reported occasionally and it seems to resolve itself on its own and I'm suspecting some part of the Wyze servers went down and prevented access? Though Error 400 is usually saying its the requestor that's the problem.

The hard part is that the error stems from wyze-sdk which is trying to reach out to the Wyze servers so the issue is either the information you're providing for logging in or the Wyze servers themselves.

drewdah commented 11 months ago

I tried a few times when writing up the bug to grab screenshots and just tried again now this morning and got the same error. I'm able to log into the wyze.com site with the same copy/pasted username and password, so I tried deleting my API key again and creating a new one and that seems to have solved it.

Maybe Wyze is invalidating or blocking keys? I know they rate limit if we poll too often

Tadimsky commented 7 months ago

I just ran into this same issue after setting it up yesterday, today it's failing with the same 400 error. Once you re-generated the token did it continue working for you?