SecKatie / ha-wyzeapi

Home Assistant Integration for Wyze devices.
722 stars 112 forks source link

[Bug] Unable to login to Wyze #487

Closed domgregori closed 9 months ago

domgregori commented 1 year ago

Describe the bug Getting Unknown error occurred when trying to login with credentials

To Reproduce Steps to reproduce the behavior:

  1. Enter credentials
  2. Click on Submit
  3. See error: Unknown error occurred

Expected behavior Login into wyze, ask for 2FA

System configuration System: Docker on Ubuntu 20.04.6 LTS HA Version: Home Assistant 2023.6.3, Frontend 20230608.0 - latest, HACS 1.32.1 ha-wyzeapi Version: 0.1.19 WyzeApi Version: 0.5.19

home-assistant.log

Source: custom_components/wyzeapi/config_flow.py:59
Integration: Wyze Home Assistant Integration ([documentation](https://github.com/JoshuaMulliken/ha-wyzeapi#readme), [issues](https://github.com/JoshuaMulliken/ha-wyzeapi/issues))
First occurred: 6:12:42 PM (1 occurrences)
Last logged: 6:12:42 PM
Error handling request

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 85, in security_filter_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 80, in ban_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 236, in auth_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 148, in handle
    result = await handler(request, **request.match_info)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 181, in post
    return await super().post(request, flow_id)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 72, in wrapper
    result = await method(view, request, data, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 110, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 271, in async_configure
    result = await self._async_handle_step(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 367, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/wyzeapi/config_flow.py", line 59, in async_step_user
    await self.client.login(
  File "/usr/local/lib/python3.11/site-packages/wyzeapy/__init__.py", line 81, in login
    await self._auth_lib.get_token_with_username_password(email, password)
  File "/usr/local/lib/python3.11/site-packages/wyzeapy/wyze_auth_lib.py", line 104, in get_token_with_username_password
    response_json = await self.post("https://auth-prod.api.wyze.com/user/login", headers=headers,
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/wyzeapy/wyze_auth_lib.py", line 232, in post
    return await response.json()
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/client_reqrep.py", line 1104, in json
    raise ContentTypeError(
aiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: text/html', url=URL('https://auth-prod.api.wyze.com/user/login')
domgregori commented 1 year ago

Seems as though cloudfront is blocking the request. When I curl I get:

server: CloudFront
date: Wed, 28 Jun 2023 23:44:58 GMT
content-type: text/html
content-length: 919
x-cache: Error from cloudfront
via: 1.1 c37b7e69b10b90188d923a2d02d4e71a.cloudfront.net (CloudFront)
x-amz-cf-pop: DUS51-P4
x-amz-cf-id: FlWQ6o6kw4e04bTcWHyQ8ao0cXZeJ-bVGq_v69RDFsWVszW5yqGVQw==

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE>ERROR: The request could not be satisfied</TITLE>
</HEAD><BODY>
<H1>403 ERROR</H1>
<H2>The request could not be satisfied.</H2>
<HR noshade size="1px">
Request blocked.
We can't connect to the server for this app or website at this time. There might be too much traffic or a configuration error. Try again later, or contact the app or website owner.
<BR clear="all">
If you provide content to customers through CloudFront, you can find steps to troubleshoot and help prevent this error by reviewing the CloudFront documentation.
<BR clear="all">
<HR noshade size="1px">
<PRE>
Generated by cloudfront (CloudFront)
Request ID: FlWQ6o6kw4e04bTcWHyQ8ao0cXZeJ-bVGq_v69RDFsWVszW5yqGVQw==
</PRE>
<ADDRESS>
</ADDRESS>
</BODY></HTML>

And when I do the same curl from another machine I get the access_token and refresh_token. I'm not sure why since I was using wyze before in HA fine. I had to change my password and I removed wyze and reinstalled it via HACS. Maybe a catch needs to be added for this error when logging in?

domgregori commented 1 year ago

For some reason auth-prod.api.wyze.com is blocked, but api.wyzecam.com is not.

Is it possible to optionally supply the plugin with auth and refresh tokens in lieu of username/password?

SecKatie commented 11 months ago

Is it possible to optionally supply the plugin with auth and refresh tokens in lieu of username/password?

No unfortunately that is not possible right now

iamwilliamdiaz commented 11 months ago

Still an issue. Getting "Unknown error occurred" when providing all the credentials, key id and api key

SecKatie commented 11 months ago

@iamwilliamdiaz can you remove the integration, allow time for the rate limit to deactivate and try again later?

VincePimentel commented 11 months ago

I've gotten this issue too lately. Removing and reinstalling this integration didn't work. When asking for credentials, it has 4 fields, 1 for username, 1 for password and 2 blank ones.

hmakmur commented 11 months ago

I have exactly the same issue as well. Dont know why it failed after HA is restarted and now I can't use it.

SkinSpa commented 11 months ago

Same issue here. I’ve been trying for the past week to generate key and api and always the same error message: « unknown error occurred. »

brg468 commented 11 months ago

Same issue here. I’ve been trying for the past week to generate key and api and always the same error message: « unknown error occurred. »

You’re having trouble generating the key and api or logging into HA with it?

You're getting unknown error occurred on the frontend login page right? Have you checked the HA logs to see what the actual error message is?

skier233 commented 11 months ago

I generated an api key and id and entered it alongside my email and password and it also didn't work. As an aside, it's an absolute pain to manually enter these into the boxes since you've disabled copy paste for the input boxes.

brg468 commented 11 months ago

I’m not sure what browser your using but copy/paste definitely works on chrome, iOS app and safari.

iamwilliamdiaz commented 11 months ago

I removed Wyze integration from HASS and then reinstalled to solve the problem. Give a try!

On Wed, Aug 9, 2023 at 9:11 AM skier233 @.***> wrote:

I generated an api key and id and entered it alongside my email and password and it also didn't work. As an aside, it's an absolute pain to manually enter these into the boxes since you've disabled copy paste for the input boxes.

— Reply to this email directly, view it on GitHub https://github.com/SecKatie/ha-wyzeapi/issues/487#issuecomment-1671301509, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACPYPSWQWQRTY243VIKFUNLXUOEALANCNFSM6AAAAAAZXXFCBI . You are receiving this because you were mentioned.Message ID: @.***>

-- This electronic mail (including any attachments) may contain information that is privileged, confidential, and/or otherwise protected from disclosure to anyone other than its intended recipient(s). Do not share this message without written consent even if intended for quality control. Any dissemination or use of this electronic mail or its contents (including any attachments) by persons other than the intended recipient(s) is strictly prohibited.

SkinSpa commented 11 months ago

I did too but it didn't fix the issue

In Wellness, Johann

On Wed, Aug 9, 2023 at 9:15 AM W Diaz @.***> wrote:

I removed Wyze integration from HASS and then reinstalled to solve the problem. Give a try!

On Wed, Aug 9, 2023 at 9:11 AM skier233 @.***> wrote:

I generated an api key and id and entered it alongside my email and password and it also didn't work. As an aside, it's an absolute pain to manually enter these into the boxes since you've disabled copy paste for the input boxes.

— Reply to this email directly, view it on GitHub < https://github.com/SecKatie/ha-wyzeapi/issues/487#issuecomment-1671301509>,

or unsubscribe < https://github.com/notifications/unsubscribe-auth/ACPYPSWQWQRTY243VIKFUNLXUOEALANCNFSM6AAAAAAZXXFCBI>

. You are receiving this because you were mentioned.Message ID: @.***>

-- This electronic mail (including any attachments) may contain information that is privileged, confidential, and/or otherwise protected from disclosure to anyone other than its intended recipient(s). Do not share this message without written consent even if intended for quality control. Any dissemination or use of this electronic mail or its contents (including any attachments) by persons other than the intended recipient(s) is strictly prohibited.

— Reply to this email directly, view it on GitHub https://github.com/SecKatie/ha-wyzeapi/issues/487#issuecomment-1671307572, or unsubscribe https://github.com/notifications/unsubscribe-auth/AN7EFO55HNKMWOGK3GVISL3XUOEPBANCNFSM6AAAAAAZXXFCBI . You are receiving this because you commented.Message ID: @.***>

hmakmur commented 11 months ago

I have exactly the same issue as well. Dont know why it failed after HA is restarted and now I can't use it.

I just retried again and there are now 4 fields with labels. Before 2 important fields (KeyID & API Key field were blanks) I did not know there is a requirement for keyid and api key which prompt me to read Creating an API Key. Once I created the API Key, reconfiguration now works. Thank you!

skier233 commented 11 months ago

Uninstalling wyze with HACS and reinstalling it fixed it for me.

James62370 commented 11 months ago

I've uninstalled the add-on and then re-installed it. Things work for about 3 days to a week and then I get the login errors again. I've created another Wyze API key hoping this will ultimately resolve the issue. Not sure why I keep getting an access token error. This is the third time doing this. I have about 37 Wyze devices, which I have to put in their appropriate locations each time I uninstall the integration. Greatly appreciated if anyone can shed some light on this. Would be nice if I can just re-login without having the remove the integration.

denverwombat commented 11 months ago

I've had two API keys expire in the last 5 days. On Sunday I got the latest module, generated my first API key, and my Wyze lights were working again. By Monday, they weren't responding to HA, and I got authentication errors in the logs when rebooting HA.

So I generated a 2nd new Wyze API key. It worked for about 48 hours.

I'm only using 3 Wyze bulbs, and only turn them on/off a handful of times a day, so there's not a ton of traffic to hit any API limits.

denverwombat commented 11 months ago

Would be nice if I can just re-login without having the remove the integration.

If you click "Add Entry" while viewing config/integrations/integration/wyzeapi the window for user/pw/API credentials pops up again to re-auth. From there I was able to enter a new API key. The error condition disappears from the Wyze module, but I couldn't control my Wyze devices until I restarted HA. Still, much easier than fully removing/re-installing the Wyze module.

James62370 commented 11 months ago

Thank you denverwombat, that will be very helpful if it happens again in the future. I appreciate your help!

denverwombat commented 11 months ago

I tried to find anything useful on the Wyze website hoping to find more error details, or an API call limit published, or a forum; no luck. The API key page seems to be the entirety of the dev site AFAICT.

James62370 commented 11 months ago

Had to re-login and authenticate again. Denverwombat's suggestion worked and I didn't have to remove the integration. Below are the two error logs. Hope this can shed some light on why this may be happening.


Logger: wyzeapy.services.update_manager Source: /usr/local/lib/python3.11/site-packages/wyzeapy/services/update_manager.py:46 First occurred: 10:49:58 AM (6 occurrences) Last logged: 10:51:29 AM

Unknown error happened during updating device info Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/wyzeapy/services/update_manager.py", line 42, in update self.device = await self.service.update(self.device) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/wyzeapy/services/lock_service.py", line 18, in update device_info = await self._get_lock_info(lock) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/wyzeapy/services/base_service.py", line 512, in _get_lock_info check_for_errors_lock(response_json) File "/usr/local/lib/python3.11/site-packages/wyzeapy/utils.py", line 94, in check_for_errors_lock raise UnknownApiError(response_json) wyzeapy.exceptions.UnknownApiError: {'ReqID': '19fd96f898', 'ErrNo': '15202', 'ErrMsg': 'USER_ACCOUNT_NOT_EXIST'}--------------------------------------------------------------

Logger: wyzeapy.services.update_manager Source: /usr/local/lib/python3.11/site-packages/wyzeapy/services/update_manager.py:46 First occurred: 10:49:55 AM (48 occurrences) Last logged: 10:51:28 AM

Unknown error happened during updating device info Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/wyzeapy/services/update_manager.py", line 42, in update self.device = await self.service.update(self.device) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/wyzeapy/services/camera_service.py", line 41, in update camera.device_params = await self.get_updated_params(camera.mac) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/wyzeapy/services/base_service.py", line 131, in get_updated_params await self.get_object_list() File "/usr/local/lib/python3.11/site-packages/wyzeapy/services/base_service.py", line 122, in get_object_list check_for_errors_standard(response_json) File "/usr/local/lib/python3.11/site-packages/wyzeapy/utils.py", line 80, in check_for_errors_standard raise AccessTokenError wyzeapy.exceptions.AccessTokenError

denverwombat commented 11 months ago

My most recent key expired, this time I tried waiting it out rather than starting a new key right away.

New key: Sunday night Stopped working: Wednesday night Started working again: Thursday night

So maybe it's rate limiting that kicks in? Anybody else able to reproduce this?

denverwombat commented 11 months ago

Well, that lasted about 10-14 hours before the key stopped working again.

brg468 commented 11 months ago

I’m really at a loss for why this is happening to some but not others. I’ve had 2 instances running for at least 4-5 days and have had no issues. Is there anything you can think of that’s unique about your setup? Are the error messages the same as before?

James62370 commented 11 months ago

Maybe this should be merged, seems related... https://github.com/SecKatie/ha-wyzeapi/issues/509

github-actions[bot] commented 10 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] commented 9 months ago

This issue was closed because it has been stalled for 5 days with no activity.