SecKatie / ha-wyzeapi

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

2 step authentication error login #272

Closed dony71 closed 2 years ago

dony71 commented 2 years ago

Try to install Wyze Home Assistant Integraion on Home Assistant 2021.10.6 Get error after put login and password

2021-10-28 15:12:55 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.8/site-packages/aiohttp/connector.py", line 969, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore  # noqa
  File "/usr/local/lib/python3.8/asyncio/base_events.py", line 1050, in create_connection
    transport, protocol = await self._create_connection_transport(
  File "/usr/local/lib/python3.8/asyncio/base_events.py", line 1080, in _create_connection_transport
    await waiter
  File "/usr/local/lib/python3.8/asyncio/sslproto.py", line 529, in data_received
    ssldata, appdata = self._sslpipe.feed_ssldata(data)
  File "/usr/local/lib/python3.8/asyncio/sslproto.py", line 189, in feed_ssldata
    self._sslobj.do_handshake()
  File "/usr/local/lib/python3.8/ssl.py", line 944, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1125)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.8/site-packages/aiohttp/web_protocol.py", line 422, in _handle_request
    resp = await self._request_handler(request)
  File "/srv/homeassistant/lib/python3.8/site-packages/aiohttp/web_app.py", line 499, in _handle
    resp = await handler(request)
  File "/srv/homeassistant/lib/python3.8/site-packages/aiohttp/web_middlewares.py", line 119, in impl
    return await handler(request)
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/components/http/security_filter.py", line 60, in security_filter_middleware
    return await handler(request)
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/components/http/forwarded.py", line 220, in forwarded_middleware
    return await handler(request)
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/components/http/request_context.py", line 24, in request_context_middleware
    return await handler(request)
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/components/http/ban.py", line 78, in ban_middleware
    return await handler(request)
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/components/http/auth.py", line 144, in auth_middleware
    return await handler(request)
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/components/http/view.py", line 136, in handle
    result = await result
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/components/config/config_entries.py", line 157, in post
    return await super().post(request, flow_id)
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/components/http/data_validator.py", line 62, in wrapper
    result = await method(view, request, *args, **kwargs)
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/data_entry_flow.py", line 111, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/data_entry_flow.py", line 198, in async_configure
    result = await self._async_handle_step(flow, cur_step["step_id"], user_input)
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/data_entry_flow.py", line 256, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
  File "/home/homeassistant/.homeassistant/custom_components/wyzeapi/config_flow.py", line 53, in async_step_user
    await self.client.login(
  File "/srv/homeassistant/lib/python3.8/site-packages/wyzeapy/__init__.py", line 79, in login
    await self._auth_lib.get_token_with_username_password(email, password)
  File "/srv/homeassistant/lib/python3.8/site-packages/wyzeapy/wyze_auth_lib.py", line 105, in get_token_with_username_password
    response_json = await self.post("https://auth-prod.api.wyze.com/user/login", headers=headers,
  File "/srv/homeassistant/lib/python3.8/site-packages/wyzeapy/wyze_auth_lib.py", line 221, in post
    response = await _session.post(url, json=json, headers=headers, data=data)
  File "/srv/homeassistant/lib/python3.8/site-packages/aiohttp/client.py", line 520, in _request
    conn = await self._connector.connect(
  File "/srv/homeassistant/lib/python3.8/site-packages/aiohttp/connector.py", line 535, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/srv/homeassistant/lib/python3.8/site-packages/aiohttp/connector.py", line 892, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "/srv/homeassistant/lib/python3.8/site-packages/aiohttp/connector.py", line 1051, in _create_direct_connection
    raise last_exc
  File "/srv/homeassistant/lib/python3.8/site-packages/aiohttp/connector.py", line 1020, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
  File "/srv/homeassistant/lib/python3.8/site-packages/aiohttp/connector.py", line 971, in _wrap_create_connection
    raise ClientConnectorCertificateError(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorCertificateError: Cannot connect to host auth-prod.api.wyze.com:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1125)')]
SecKatie commented 2 years ago

That appears to be a problem with your network and not the integration. If the certificate is bad you might be being "Man in the Middled" MITM.

dony71 commented 2 years ago

any idea what i should do to debug this?

JoeSchubert commented 2 years ago

It's also possible that Wyze is just experiencing issues. I've had sign-in problems multiple times since owning my Wyze products. If you sign out of your account in their app, are you able to sign back in from the same connection? (obviously, barring a MITM attack)

dony71 commented 2 years ago

no problem signing out from ios app and signing back in from the same location

JoeSchubert commented 2 years ago

no problem signing out from ios app and signing back in from the same location

Just doing a quick google search (since this is a problem stemming from aiohttp and your python install, not this integration), brought me to this answer: https://stackoverflow.com/a/53310545

are you running this on a mac?

dony71 commented 2 years ago

hass running on raspberry pi hass behind nginx reverse proxy with letsencrypt dns

JoeSchubert commented 2 years ago

Yeah, makes sense. I run a similar setup using dockerswag.

You may also want to check that some of the fixes here: https://stackoverflow.com/questions/35569042/ssl-certificate-verify-failed-with-python3 don't help.

Just curious, to narrow things down to whether it's a system-wide SSL issue, or if it's a problem with just python can you pull from https pages with curl like below?

curl -k https://raw.githubusercontent.com/JoshuaMulliken/ha-wyzeapi/master/info.md

dony71 commented 2 years ago

curl -k https://raw.githubusercontent.com/JoshuaMulliken/ha-wyzeapi/master/info.md

<!--
SPDX-FileCopyrightText: 2021 Joshua Mulliken <joshua@mulliken.net>

SPDX-License-Identifier: Apache-2.0
-->

# [Wyze Integration for Home Assistant](https://github.com/JoshuaMulliken/ha-wyzeapi)

This is a custom component to allow control of various Wyze devices in Home Assistant using the unofficial API. Please
note this mimics the Wyze app and therefore access may be cut off at anytime.

### Highlights of what **WyzeApi** can do

* Control Wyze Bulbs as lights through HA
* Control Wyze Plugs as switches through HA
* Use Wyze Cameras as motion sensors
* Turn on and off Wyze Cameras
* Lock, unlock, and view status of lock and door for the Wyze Lock

## Support

If you feel like my work has been valuable to you I welcome your support through BuyMeACoffee!

<a href="https://www.buymeacoffee.com/joshmulliken" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" style="height: 51px !important;width: 217px !important;" ></a>

## Useful Links

* [README](https://github.com/JoshuaMulliken/ha-wyzeapi/blob/master/README.md)
* [Repository](https://github.com/JoshuaMulliken/ha-wyzeapi)
JoeSchubert commented 2 years ago

curl -k https://raw.githubusercontent.com/JoshuaMulliken/ha-wyzeapi/master/info.md

<!--
SPDX-FileCopyrightText: 2021 Joshua Mulliken <joshua@mulliken.net>

SPDX-License-Identifier: Apache-2.0
-->

# [Wyze Integration for Home Assistant](https://github.com/JoshuaMulliken/ha-wyzeapi)

This is a custom component to allow control of various Wyze devices in Home Assistant using the unofficial API. Please
note this mimics the Wyze app and therefore access may be cut off at anytime.

### Highlights of what **WyzeApi** can do

* Control Wyze Bulbs as lights through HA
* Control Wyze Plugs as switches through HA
* Use Wyze Cameras as motion sensors
* Turn on and off Wyze Cameras
* Lock, unlock, and view status of lock and door for the Wyze Lock

## Support

If you feel like my work has been valuable to you I welcome your support through BuyMeACoffee!

<a href="https://www.buymeacoffee.com/joshmulliken" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" style="height: 51px !important;width: 217px !important;" ></a>

## Useful Links

* [README](https://github.com/JoshuaMulliken/ha-wyzeapi/blob/master/README.md)
* [Repository](https://github.com/JoshuaMulliken/ha-wyzeapi)

That means that it's just something with python then.

Try the pip command here maybe? https://stackoverflow.com/a/43855394

Ultimately, I'm just guessing though. Something with your python installation is broken...

JoeSchubert commented 2 years ago

Were you able to get your environment fixed?

These kinds of issues are why I started running the home assistant docker container. It gets old trying to figure out why something just randomly breaks in your environment. Docker containers are way better about that not happening.

JoeSchubert commented 2 years ago

I'm going to go ahead and close this since it's not an integration issue and once your python environment is fixed it will resolve itself.

dony71 commented 2 years ago

FYI The problem is when running hass in virtual env using systemd But if I run manually like /srv/homeassistant/bin/hass -c "/home/homeassistant/.homeassistant" then it's working I don't understand why