Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConnectionResetError in v2.x #362

Closed
somar05 opened this issue Sep 14, 2019 · 46 comments
Closed

ConnectionResetError in v2.x #362

somar05 opened this issue Sep 14, 2019 · 46 comments
Labels
alexapy Issue relates to the API bug Something isn't working

Comments

@somar05
Copy link

somar05 commented Sep 14, 2019

Describe the bug
Since v.1.4.1, any of the v.2.x can works

To Reproduce
Steps to reproduce the behavior:

  1. Uninstall v.1.4.1 (HACS)
  2. Install any v.2.x
  3. Login procedure to Amazon completed
  4. Restart (1, 2 ,3, times)
  5. Error during setup of component alexa_media

Expected behavior
For v1.4.1 there are no problem. Always run properly

System details

  • Home-assistant (version): 0.98.1
  • Hassio (Yes/No): Yes
  • alexa_media (version from const.py or HA startup): 2.1.2 (any 2.x)
  • alexapy (version from pip show alexapy or HA startup): 1.1.2

Logs
2019-09-14 08:33:27 ERROR (MainThread) [homeassistant.setup] Error during setup of component alexa_media
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 924, in _wrap_create_connection
await self._loop.create_connection(*args, **kwargs))
File "/usr/local/lib/python3.7/asyncio/base_events.py", line 981, in create_connection
ssl_handshake_timeout=ssl_handshake_timeout)
File "/usr/local/lib/python3.7/asyncio/base_events.py", line 1009, in _create_connection_transport
await waiter
ConnectionResetError

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

Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/setup.py", line 168, in _async_setup_component
hass, processed_config
File "/config/custom_components/alexa_media/init.py", line 132, in async_setup
await login.login_with_cookie()
File "/usr/local/lib/python3.7/site-packages/alexapy/alexalogin.py", line 165, in login_with_cookie
await self.login(cookies=self._cookies)
File "/usr/local/lib/python3.7/site-packages/alexapy/alexalogin.py", line 312, in login
if (cookies and await self.test_loggedin(cookies)):
File "/usr/local/lib/python3.7/site-packages/alexapy/alexalogin.py", line 233, in test_loggedin
ssl=self._ssl
File "/usr/local/lib/python3.7/site-packages/aiohttp/client.py", line 476, in _request
timeout=real_timeout
File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 522, in connect
proto = await self._create_connection(req, traces, timeout)
File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 854, in _create_connection
req, traces, timeout)
File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 992, in _create_direct_connection
raise last_exc
File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 974, in _create_direct_connection
req=req, client_error=client_error)
File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 931, in _wrap_create_connection
raise client_error(req.connection_key, exc) from exc

Additional context
Login zone: amazon.es

@alandtse alandtse added alexapy Issue relates to the API bug Something isn't working labels Sep 14, 2019
@alandtse

This comment has been minimized.

@somar05
Copy link
Author

somar05 commented Sep 15, 2019

Thanks, Alan Tse. Here the info:

Step 1:
Initial scene: v.1.4.1 installed from HACS working properly and no errors found in log, excepts related to 'No entity id specified shuffle, do not diturb switch, etc' for some devices (known issues)

Step 2:
Upgrade from v.1.4.1 to v.2.1.2 without deleting the 'pickle file'. After 1st boot it looks works fine (alexa announce, etc, etc). No login procedure required. The only error found is as follow:
2019-09-15 10:57:12 ERROR (MainThread) [homeassistant.components.alarm_control_panel] Setup of platform alexa_media is taking longer than 60 seconds. Startup will proceed without waiting any longer.
But, again, it looks woks fine (media player, announce, etc), and not errors related with switches (shuffle, repeat, ...)

Step 3:
2nd reboot to confirm that everything is working fine. Then, the component fail again. It looks can not connect to amazon.es:443

2019-09-15 11:04:51 ERROR (MainThread) [homeassistant.setup] Error during setup of component alexa_media
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 924, in _wrap_create_connection
    await self._loop.create_connection(*args, **kwargs))
  File "/usr/local/lib/python3.7/asyncio/base_events.py", line 981, in create_connection
    ssl_handshake_timeout=ssl_handshake_timeout)
  File "/usr/local/lib/python3.7/asyncio/base_events.py", line 1009, in _create_connection_transport
    await waiter
ConnectionResetError

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

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 168, in _async_setup_component
    hass, processed_config
  File "/config/custom_components/alexa_media/__init__.py", line 132, in async_setup
    await login.login_with_cookie()
  File "/usr/local/lib/python3.7/site-packages/alexapy/alexalogin.py", line 165, in login_with_cookie
    await self.login(cookies=self._cookies)
  File "/usr/local/lib/python3.7/site-packages/alexapy/alexalogin.py", line 312, in login
    if (cookies and await self.test_loggedin(cookies)):
  File "/usr/local/lib/python3.7/site-packages/alexapy/alexalogin.py", line 233, in test_loggedin
    ssl=self._ssl
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client.py", line 476, in _request
    timeout=real_timeout
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 522, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 854, in _create_connection
    req, traces, timeout)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 992, in _create_direct_connection
    raise last_exc
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 974, in _create_direct_connection
    req=req, client_error=client_error)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 931, in _wrap_create_connection
    raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host alexa.amazon.es:443 ssl:<ssl.SSLContext object at 0x728053f0> [None]

Step 4:
Downgrade again through HACS to v.1.4.1 and restart. Then, working properly with the only errors related to 'switches'

For info: the config section in configuration.yalm

alexa_media:
  accounts:
    - email: !secret amazon_email
      password: !secret amazon_pass
      url: amazon.es
      debug: True

@alandtse

This comment has been minimized.

@somar05

This comment has been minimized.

@alandtse

This comment has been minimized.

@alandtse alandtse changed the title No way to run any v2.x. ConnectionResetError in v2.x Sep 17, 2019
@somar05

This comment has been minimized.

@alandtse

This comment has been minimized.

@somar05
Copy link
Author

somar05 commented Sep 18, 2019

Hi Alan Tse,

No luck. Same error:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 924, in _wrap_create_connection
    await self._loop.create_connection(*args, **kwargs))
  File "/usr/local/lib/python3.7/asyncio/base_events.py", line 981, in create_connection
    ssl_handshake_timeout=ssl_handshake_timeout)
  File "/usr/local/lib/python3.7/asyncio/base_events.py", line 1009, in _create_connection_transport
    await waiter
ConnectionResetError

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

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 168, in _async_setup_component
    hass, processed_config
  File "/config/custom_components/alexa_media/__init__.py", line 132, in async_setup
    await login.login_with_cookie()
  File "/usr/local/lib/python3.7/site-packages/alexapy/alexalogin.py", line 165, in login_with_cookie
    await self.login(cookies=self._cookies)
  File "/usr/local/lib/python3.7/site-packages/alexapy/alexalogin.py", line 312, in login
    if (cookies and await self.test_loggedin(cookies)):
  File "/usr/local/lib/python3.7/site-packages/alexapy/alexalogin.py", line 233, in test_loggedin
    ssl=self._ssl
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client.py", line 476, in _request
    timeout=real_timeout
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 522, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 854, in _create_connection
    req, traces, timeout)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 992, in _create_direct_connection
    raise last_exc
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 974, in _create_direct_connection
    req=req, client_error=client_error)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 931, in _wrap_create_connection
    raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host alexa.amazon.es:443 ssl:<ssl.SSLContext object at 0x72f0bbb0> [None]```

@somar05
Copy link
Author

somar05 commented Sep 19, 2019

Now, testing v2.2.0. I think is a related problem.
Steps:

  1. Update from v1.4.1 to v2.2.0
  2. Delete pickle file
  3. Reboot
  4. Integration confuguration sucesfully (note the sms code send by Amazon for verification has to be typed in a blank/no title box)
  5. Reboot

Error:

2019-09-19 15:28:41 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry [email protected] - amazon.es for alexa_media
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 924, in _wrap_create_connection
    await self._loop.create_connection(*args, **kwargs))
  File "/usr/local/lib/python3.7/asyncio/base_events.py", line 981, in create_connection
    ssl_handshake_timeout=ssl_handshake_timeout)
  File "/usr/local/lib/python3.7/asyncio/base_events.py", line 1009, in _create_connection_transport
    await waiter
ConnectionResetError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 190, in async_setup
    hass, self
  File "/config/custom_components/alexa_media/__init__.py", line 172, in async_setup_entry
    await login.login_with_cookie()
  File "/usr/local/lib/python3.7/site-packages/alexapy/alexalogin.py", line 168, in login_with_cookie
    await self.login(cookies=self._cookies)
  File "/usr/local/lib/python3.7/site-packages/alexapy/alexalogin.py", line 331, in login
    if (cookies and await self.test_loggedin(cookies)):
  File "/usr/local/lib/python3.7/site-packages/alexapy/alexalogin.py", line 246, in test_loggedin
    ssl=self._ssl
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client.py", line 476, in _request
    timeout=real_timeout
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 522, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 854, in _create_connection
    req, traces, timeout)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 992, in _create_direct_connection
    raise last_exc
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 974, in _create_direct_connection
    req=req, client_error=client_error)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 931, in _wrap_create_connection
    raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host alexa.amazon.es:443 ssl:<ssl.SSLContext object at 0x72d0e330>```

@Pirol62
Copy link

Pirol62 commented Sep 20, 2019

The history for me:

  1. Upgrade: It worked for the fist time perfectly. I did not delete the pickle.
  2. Deleted the config entry and restart - worked perfectly.
  3. Restart due to other reasons - I had to restart a second time then it worked
  4. Restarted once more - no chance. Tried 4 times then rolled back to 1.4.1. See Error log in HA thread.

@alandtse
Copy link
Owner

Need some testers on a theory on why we're seeing disconnects. You'll need to be comfortable directly editing your alexalogin.py. Please report back what happens if you make each of these edits. If it works with the first option, you can stop.

At line 55 add one additional line.

Original:

        self._ssl = ssl.create_default_context(
            purpose=ssl.Purpose.SERVER_AUTH, cafile=certifi.where()
        )
        self._cookies: Optional[Dict[Text, Text]] = {}

Option 1 (False):

        self._ssl = ssl.create_default_context(
            purpose=ssl.Purpose.SERVER_AUTH, cafile=certifi.where()
        )
        self._ssl = False
        self._cookies: Optional[Dict[Text, Text]] = {}

Option 2 (None):

        self._ssl = ssl.create_default_context(
            purpose=ssl.Purpose.SERVER_AUTH, cafile=certifi.where()
        )
        self._ssl = None
        self._cookies: Optional[Dict[Text, Text]] = {}

I'm wondering if all the disconnect errors are from enforcing SSL. When we had requests in the v1.x branch, we basically didn't check the SSL cert. Make a backup or just delete the extra line if you want to go back to what we have now.

@somar05
Copy link
Author

somar05 commented Sep 20, 2019

Alan Tse, is it possible to do this test under Hassio addon? I mean, where is located the alexalogin.py file?

@Beertje135
Copy link
Contributor

Alan Tse, is it possible to do this test under Hassio addon? I mean, where is located the alexalogin.py file?

idem. Would like to help but can't seem to find the file. (Hassio)

@alandtse
Copy link
Owner

There is a way. Follow the instructions for installing alexapy manually in your /config directory. The specific command is:
pip3 install --target /config --no-dependencies alexapy
Then you can manually edit it using the Configurator add on.

To restore to the defaults, you can delete the /config/alexapy directory and it'll use the default.

@Beertje135
Copy link
Contributor

Beertje135 commented Sep 20, 2019

Option 1:

2019-09-20 09:52:32 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry emailadres - amazon.co.uk for alexa_media
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 924, in _wrap_create_connection
await self._loop.create_connection(*args, **kwargs))
File "/usr/local/lib/python3.7/asyncio/base_events.py", line 981, in create_connection
ssl_handshake_timeout=ssl_handshake_timeout)
File "/usr/local/lib/python3.7/asyncio/base_events.py", line 1009, in _create_connection_transport
await waiter
ConnectionResetError

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

Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 190, in async_setup
hass, self
File "/config/custom_components/alexa_media/init.py", line 172, in async_setup_entry
await login.login_with_cookie()
File "/config/alexapy/alexalogin.py", line 169, in login_with_cookie
await self.login(cookies=self._cookies)
File "/config/alexapy/alexalogin.py", line 332, in login
if (cookies and await self.test_loggedin(cookies)):
File "/config/alexapy/alexalogin.py", line 247, in test_loggedin
ssl=self._ssl
File "/usr/local/lib/python3.7/site-packages/aiohttp/client.py", line 476, in _request
timeout=real_timeout
File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 522, in connect
proto = await self._create_connection(req, traces, timeout)
File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 854, in _create_connection
req, traces, timeout)
File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 992, in _create_direct_connection
raise last_exc
File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 974, in _create_direct_connection
req=req, client_error=client_error)
File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 931, in _wrap_create_connection
raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host alexa.amazon.co.uk:443 ssl:False [None]

@Beertje135
Copy link
Contributor

Option 2:
Succes - Devices are loaded and no error for ssl.

Other problems:
No update on the device states
+
2019-09-20 10:17:44 WARNING (MainThread) [aiohttp.websocket] websocket connection is closing.
2019-09-20 10:17:44 WARNING (MainThread) [aiohttp.websocket] websocket connection is closing.
2019-09-20 10:17:44 WARNING (MainThread) [aiohttp.websocket] websocket connection is closing.

@alandtse
Copy link
Owner

Thanks @Beertje135. Did the fix persist through reboots?

For the update issue, check #374.

@Beertje135
Copy link
Contributor

After restart no problem. Reboot didn't work so had to cut power and reboot that way.
After that problem is back.

2019-09-20 10:54:22 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry emailadres - amazon.co.uk for alexa_media
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 924, in _wrap_create_connection
await self._loop.create_connection(*args, **kwargs))
File "/usr/local/lib/python3.7/asyncio/base_events.py", line 981, in create_connection
ssl_handshake_timeout=ssl_handshake_timeout)
File "/usr/local/lib/python3.7/asyncio/base_events.py", line 1009, in _create_connection_transport
await waiter
ConnectionResetError

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

Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 190, in async_setup
hass, self
File "/config/custom_components/alexa_media/init.py", line 172, in async_setup_entry
await login.login_with_cookie()
File "/config/alexapy/alexalogin.py", line 169, in login_with_cookie
await self.login(cookies=self._cookies)
File "/config/alexapy/alexalogin.py", line 332, in login
if (cookies and await self.test_loggedin(cookies)):
File "/config/alexapy/alexalogin.py", line 247, in test_loggedin
ssl=self._ssl
File "/usr/local/lib/python3.7/site-packages/aiohttp/client.py", line 476, in _request
timeout=real_timeout
File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 522, in connect
proto = await self._create_connection(req, traces, timeout)
File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 854, in _create_connection
req, traces, timeout)
File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 992, in _create_direct_connection
raise last_exc
File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 974, in _create_direct_connection
req=req, client_error=client_error)
File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 931, in _wrap_create_connection
raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host alexa.amazon.co.uk:443 ssl:None [None]

@alandtse
Copy link
Owner

Ok, let's try this fix. Apparently other components ran into this in HA so this is the fix they proposed.

@Beertje135
Copy link
Contributor

Beertje135 commented Sep 20, 2019

doesn't seem to help. After restart the problem is back.

PS: before implementation of:
fix 1 +
fix states update
There were two extra files in the config folder alexa_media....html. Now they are gone (or not recreated after restart)

@Beertje135
Copy link
Contributor

2019-09-20 11:34:54 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry [email protected] - amazon.co.uk for alexa_media
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 924, in _wrap_create_connection
await self._loop.create_connection(*args, **kwargs))
File "/usr/local/lib/python3.7/asyncio/base_events.py", line 981, in create_connection
ssl_handshake_timeout=ssl_handshake_timeout)
File "/usr/local/lib/python3.7/asyncio/base_events.py", line 1009, in _create_connection_transport
await waiter
ConnectionResetError

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

Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 190, in async_setup
hass, self
File "/config/custom_components/alexa_media/init.py", line 172, in async_setup_entry
await login.login_with_cookie()
File "/config/alexapy/alexalogin.py", line 169, in login_with_cookie
await self.login(cookies=self._cookies)
File "/config/alexapy/alexalogin.py", line 337, in login
if (cookies and await self.test_loggedin(cookies)):
File "/config/alexapy/alexalogin.py", line 247, in test_loggedin
ssl=self._ssl
File "/usr/local/lib/python3.7/site-packages/aiohttp/client.py", line 476, in _request
timeout=real_timeout
File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 522, in connect
proto = await self._create_connection(req, traces, timeout)
File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 854, in _create_connection
req, traces, timeout)
File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 992, in _create_direct_connection
raise last_exc
File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 974, in _create_direct_connection
req=req, client_error=client_error)
File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 931, in _wrap_create_connection
raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host alexa.amazon.co.uk:443 ssl:None [None]

@alandtse
Copy link
Owner

Did another change in the fix. Please let me know if it helps.

@somar05
Copy link
Author

somar05 commented Sep 21, 2019

Tested with no luck.
Details:

  • Hassio v0.99.2
  • Upgrade from v1.4.1 to v2.2.0 and mr !80
  • Pickle file not deleted (reused)
  • Installation with no issues. Reboot not required. I can see "integration section" with all alexa devices. Announce and media player working properly
  • After 1st and subsequents reboots, again connection errors:
2019-09-21 08:30:41 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry [email protected] - amazon.es for alexa_media
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 924, in _wrap_create_connection
    await self._loop.create_connection(*args, **kwargs))
  File "/usr/local/lib/python3.7/asyncio/base_events.py", line 981, in create_connection
    ssl_handshake_timeout=ssl_handshake_timeout)
  File "/usr/local/lib/python3.7/asyncio/base_events.py", line 1009, in _create_connection_transport
    await waiter
ConnectionResetError

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

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 190, in async_setup
    hass, self
  File "/config/custom_components/alexa_media/__init__.py", line 172, in async_setup_entry
    await login.login_with_cookie()
  File "/config/alexapy/alexalogin.py", line 168, in login_with_cookie
    await self.login(cookies=self._cookies)
  File "/config/alexapy/alexalogin.py", line 339, in login
    if (cookies and await self.test_loggedin(cookies)):
  File "/config/alexapy/alexalogin.py", line 246, in test_loggedin
    ssl=self._ssl
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client.py", line 476, in _request
    timeout=real_timeout
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 522, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 854, in _create_connection
    req, traces, timeout)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 992, in _create_direct_connection
    raise last_exc
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 974, in _create_direct_connection
    req=req, client_error=client_error)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 931, in _wrap_create_connection
    raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host alexa.amazon.es:443 ssl:<ssl.SSLContext object at 0x72cd0670> [None]```

@somar05
Copy link
Author

somar05 commented Sep 21, 2019

Just a note. After the test described in my previous comment, I have downgraded again to v1.4.1 and working. However, 'integration' is now visible in config section and looks show properly information (name, firmware, switches,...)

@alandtse
Copy link
Owner

@somar05 Thanks for testing. Yes, that is a side effect of loading once with Config Flow. It'll create the necessary entries and then it'll remember your devices even in 1.4.1. However, since it's not directly connected anymore through the component, no idea when it'll break. ;)

I'll probably need to slowly work through the error so will have a few edits here and there in the next few hours.

@Beertje135
Copy link
Contributor

Beertje135 commented Sep 21, 2019

Just to give some feedback after a night of using some fixes.

For now I have the fix for the status updates +
Option 2 (None):

        self._ssl = ssl.create_default_context(
            purpose=ssl.Purpose.SERVER_AUTH, cafile=certifi.where()
        )
        self._ssl = None
        self._cookies: Optional[Dict[Text, Text]] = {}

After restart the above error ssl - Deleted Integration - Reconnected integration
And since yesterday everything is working great. Very stable (seems somehow more stable then before).
The big problem is the restart/reboot.

Anyway I can help? if you need more tests let us know.

@alandtse
Copy link
Owner

Ok, new build, same link. One thing that may help is to enable you have advanced debugging on and providing the log right before the error so I can see where you are in the process. Please scrub your logs of the cookie data like I have as this level of debugging does provide login info.

I suspect you should see something like:

2019-09-21 01:04:32 DEBUG (MainThread) [alexapy.alexalogin] Loaded 9 cookies
 2019-09-21 01:04:32 DEBUG (MainThread) [alexapy.alexalogin] Testing whether logged in to alexa.amazon.com
 2019-09-21 01:04:32 DEBUG (MainThread) [alexapy.alexalogin] Cookies: SCRUB
 2019-09-21 01:04:32 DEBUG (MainThread) [alexapy.alexalogin] Session Cookies: SCRUB

 2019-09-21 01:04:32 DEBUG (MainThread) [alexapy.alexalogin] Header: {"User-Agent": "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36 , "Accept": "text/html,application/xhtml+xml, application/xml;q=0.9,*/*;q=0.8", "Accept-Language": "*"}
... error is likely around here

@Beertje135
Copy link
Contributor

Ok how to explain this.
Step 1: Added the new code - removed Pickle - readded to configuration.yaml for debugging - restart --> Errors
Step 2: Remove Integration - restart --> Home Assistant found new integration. But I couldn't couldn't open the connection popup (stayed white)
Step 3: Added integration with the + --> all working
Step 4: restart --> all working !!
Would like to give the errorlog but there aren't any :-)

Should restart with step 2 I think, to see what happens.

@Beertje135
Copy link
Contributor

Ok

Step 1: removed integration - removed pickle - restart --> hass found new integration + errors

2019-09-21 11:23:33 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 924, in _wrap_create_connection
await self._loop.create_connection(*args, **kwargs))
File "/usr/local/lib/python3.7/asyncio/base_events.py", line 981, in create_connection
ssl_handshake_timeout=ssl_handshake_timeout)
File "/usr/local/lib/python3.7/asyncio/base_events.py", line 1009, in _create_connection_transport
await waiter
ConnectionResetError

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

Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 73, in async_init
return await self._async_handle_step(flow, flow.init_step, data)
File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 132, in _async_handle_step
result: Dict = await getattr(flow, method)(user_input)
File "/config/custom_components/alexa_media/config_flow.py", line 138, in async_step_import
return await self.async_step_user(import_config)
File "/config/custom_components/alexa_media/config_flow.py", line 190, in async_step_user
await self.login.login_with_cookie()
File "/config/alexapy/alexalogin.py", line 168, in login_with_cookie
await self.login(cookies=self._cookies)
File "/config/alexapy/alexalogin.py", line 386, in login
ssl=self._ssl)
File "/usr/local/lib/python3.7/site-packages/aiohttp/client.py", line 476, in _request
timeout=real_timeout
File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 522, in connect
proto = await self._create_connection(req, traces, timeout)
File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 854, in _create_connection
req, traces, timeout)
File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 992, in _create_direct_connection
raise last_exc
File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 974, in _create_direct_connection
req=req, client_error=client_error)
File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 931, in _wrap_create_connection
raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host alexa.amazon.co.uk:443 ssl:<ssl.SSLContext object at 0x7f97af9d00> [None]

@Beertje135
Copy link
Contributor

step 1

@Beertje135
Copy link
Contributor

Step 2: Configure integration (like picture above) --> stays white screen

2019-09-21 11:27:27 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/aiohttp/web_protocol.py", line 418, in start
resp = await task
File "/usr/local/lib/python3.7/site-packages/aiohttp/web_app.py", line 458, in _handle
resp = await handler(request)
File "/usr/local/lib/python3.7/site-packages/aiohttp/web_middlewares.py", line 119, in impl
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/real_ip.py", line 40, in real_ip_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 73, in ban_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 231, in auth_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 128, in handle
result = await result
File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 155, in get
return await super().get(request, flow_id)
File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 78, in get
result = await self._flow_mgr.async_configure(flow_id)
File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 86, in async_configure
if cur_step.get("data_schema") is not None and user_input is not None:
AttributeError: 'NoneType' object has no attribute 'get'
2019-09-21 11:27:33 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/aiohttp/web_protocol.py", line 418, in start
resp = await task
File "/usr/local/lib/python3.7/site-packages/aiohttp/web_app.py", line 458, in _handle
resp = await handler(request)
File "/usr/local/lib/python3.7/site-packages/aiohttp/web_middlewares.py", line 119, in impl
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/real_ip.py", line 40, in real_ip_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 73, in ban_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 231, in auth_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 128, in handle
result = await result
File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 155, in get
return await super().get(request, flow_id)
File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 78, in get
result = await self._flow_mgr.async_configure(flow_id)
File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 86, in async_configure
if cur_step.get("data_schema") is not None and user_input is not None:
AttributeError: 'NoneType' object has no attribute 'get'

@Beertje135
Copy link
Contributor

Beertje135 commented Sep 21, 2019

Step 3: added integration with + --> integration works

@Beertje135
Copy link
Contributor

Step 4: restart --> back broken

2019-09-21 11:36:01 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry xxxx - amazon.co.uk for alexa_media
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 190, in async_setup
hass, self
File "/config/custom_components/alexa_media/init.py", line 172, in async_setup_entry
await login.login_with_cookie()
File "/config/alexapy/alexalogin.py", line 168, in login_with_cookie
await self.login(cookies=self._cookies)
File "/config/alexapy/alexalogin.py", line 344, in login
if (cookies and await self.test_loggedin(cookies)):
File "/config/alexapy/alexalogin.py", line 252, in test_loggedin
await self._process_resp(get_resp)
UnboundLocalError: local variable 'get_resp' referenced before assignment
2019-09-21 11:36:08 WARNING (MainThread) [homeassistant.components.vacuum] Setup of platform roomba is taking over 10 seconds.
2019-09-21 11:36:10 WARNING (MainThread) [homeassistant.components.vacuum] Platform roomba not ready yet. Retrying in 30 seconds.
2019-09-21 11:36:18 WARNING (MainThread) [homeassistant.components.script] Script script.notify_tracker_caro_thuis_ios_bert already running.
2019-09-21 11:36:23 ERROR (MainThread) [homeassistant.components.hue.light] Unable to reach bridge xxxx ()
2019-09-21 11:36:23 WARNING (MainThread) [homeassistant.components.light] Updating hue light took longer than the scheduled update interval 0:00:05
2019-09-21 11:36:29 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 162, in async_run
await self._handle_action(action, variables, context)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 246, in _handle_action
await self._actions[_determine_action(action)](action, variables, context)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 329, in _async_call_service
context=context,
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 98, in async_call_from_config
domain, service_name, service_data, blocking=blocking, context=context
File "/usr/src/homeassistant/homeassistant/core.py", line 1209, in async_call
raise ServiceNotFound(domain, service) from None
homeassistant.exceptions.ServiceNotFound: Unable to find service notify/alexa_media

@somar05
Copy link
Author

somar05 commented Sep 21, 2019

By my side, I think I have similar (if not identical) problem that @Beertje135 . But if my logs can help, I'll try the tests. Awaiting :)

@Beertje135
Copy link
Contributor

Step 5: removed integration - added integration with + --> integration works
Step 6: Restart --> integration works and no errors.

I'm lost...

@alandtse
Copy link
Owner

I just want to clarify one thing. Is the issue happening with restarting HA or rebooting the device? Or does it not make a difference?

@alandtse
Copy link
Owner

Thanks for all the help. Let's try a different direction for a little. Please restore your alexapy and let's instead attack it from the alexa_media side. Please replace your alexa_media files with changed files here.

Step 2: Configure integration (like picture above) --> stays white screen

On this issue, that may be a HA 99.0 error. Are you on 99.2?

@Beertje135
Copy link
Contributor

I just want to clarify one thing. Is the issue happening with restarting HA or rebooting the device? Or does it not make a difference?

I used the restart button in Settings, Not the reboot button under Hass.io

@Beertje135
Copy link
Contributor

arch aarch64
dev false
docker true
hassio true
os_name Linux
python_version 3.7.4
timezone Europe/Brussels
version 0.99.2
virtualenv false

@alandtse
Copy link
Owner

@Beertje135 Thanks for the clarification, please let me know how the latest set of files works (not alexapy).

@somar05
Copy link
Author

somar05 commented Sep 22, 2019

@alandtse , same here than @Beertje135 : HA 0.99.2 and restart (not reboot)

Regarding the test using the files of branch #362 (fix: add retry logic to setup_entry #381), there something strange. There are not errors related the component during the start up (I think it take now more time to finish), but when I force something to test the 'notify' I receive that (not found notify/alexa_media). Maybe I am doing something wrong:

2019-09-22 09:20:57 ERROR (MainThread) [homeassistant.components.script] Error executing script script.mensaje_garaje_encendido. Service not found for call_service at pos 1: Unable to find service notify/alexa_media
2019-09-22 09:20:57 ERROR (MainThread) [homeassistant.core] Error executing service <ServiceCall script.mensaje_garaje_encendido (c:067db813034744c0be317796e8c9baff)>
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/core.py", line 1242, in _safe_execute
    await self._execute_service(handler, service_call)
  File "/usr/src/homeassistant/homeassistant/core.py", line 1259, in _execute_service
    await handler.func(service_call)
  File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 142, in service_handler
    await script.async_turn_on(variables=service.data, context=service.context)
  File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 214, in async_turn_on
    raise err
  File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 209, in async_turn_on
    await self.script.async_run(kwargs.get(ATTR_VARIABLES), context)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 162, in async_run
    await self._handle_action(action, variables, context)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 246, in _handle_action
    await self._actions[_determine_action(action)](action, variables, context)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 329, in _async_call_service
    context=context,
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 98, in async_call_from_config
    domain, service_name, service_data, blocking=blocking, context=context
  File "/usr/src/homeassistant/homeassistant/core.py", line 1209, in async_call
    raise ServiceNotFound(domain, service) from None
homeassistant.exceptions.ServiceNotFound: Unable to find service notify/alexa_media```

@Beertje135
Copy link
Contributor

Beertje135 commented Sep 22, 2019

Ok here we go.
Step 1: removed integration / added the new code / restart --> no errors and no sign of Alexa (as expected)
Step 2: Added integration with + / make some checks --> alexa works as expected, status updates go great
Step 3: Restart --> alexa is loaded is expected and no errors + status updates.

PS: I think the alexapy/websockets upgrade was implemented also, sorry forgot to revert back. (I will check now) --> after check, it was implemented as shown in Link

@Beertje135
Copy link
Contributor

Beertje135 commented Sep 22, 2019

PS 2: before te latest fix in alexa_media I had the same errors as @somar05 on startup because notify wasn't ready when first notifications fired. But now with the fix in alexa_media it is loaded fairly fast so no errors.

@alandtse
Copy link
Owner

alandtse commented Sep 22, 2019

It's ok to have the websockets fix. I just didn't want you to have the fixes to alexapy I had proposed before.

It's not clear, are you saying everything is working except for notify? I may need to see the full log as it boots up. Are either of you on discord? It may be easier to message me(alandtse #5464) there with your startup logs.

@Beertje135
Copy link
Contributor

Step 4: Restart 2 --> all working, no errors and status updates working
Step 5: Reboot --> all working, no errors and status updates working

I think this is very great news!!

@Beertje135
Copy link
Contributor

Beertje135 commented Sep 22, 2019

It's ok to have the websockets fix. I just didn't want you to have the fixes to alexapy I had proposed before.

It's not clear, are you saying everything is working except for notify? I may need to see the full log as it boots up. Are either of you on discord? It may be easier to message me(alandtse
#5464) there with your startup logs.

Made account on discord but again it is new for me. :-)

2019-09-22 09:48:49 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for hacs which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
2019-09-22 09:48:49 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for alexa_media which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
2019-09-22 09:49:09 WARNING (MainThread) [homeassistant.setup] Setup of updater is taking over 10 seconds.
2019-09-22 09:49:09 WARNING (MainThread) [homeassistant.setup] Setup of google is taking over 10 seconds.
2019-09-22 09:49:09 WARNING (MainThread) [homeassistant.setup] Setup of hacs is taking over 10 seconds.
2019-09-22 09:49:10 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for ophaalkalender which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
2019-09-22 09:49:12 ERROR (MainThread) [homeassistant.core] Error doing job: Unclosed client session
2019-09-22 09:49:12 WARNING (MainThread) [homeassistant.setup] Setup of input_boolean is taking over 10 seconds.
2019-09-22 09:49:14 ERROR (MainThread) [homeassistant.components.hue] Error connecting to the Hue bridge at xxx.xxx.x.x
2019-09-22 09:49:14 WARNING (MainThread) [homeassistant.config_entries] Config entry for hue not ready yet. Retrying in 5 seconds.
2019-09-22 09:49:14 WARNING (MainThread) [homeassistant.setup] Setup of evohome is taking over 10 seconds.
2019-09-22 09:49:14 WARNING (MainThread) [homeassistant.setup] Setup of person is taking over 10 seconds.
2019-09-22 09:49:14 WARNING (MainThread) [homeassistant.setup] Setup of input_select is taking over 10 seconds.
2019-09-22 09:49:20 ERROR (MainThread) [homeassistant.components.unifi] Error connecting to the UniFi controller at xxx.xxx.x.x
2019-09-22 09:49:20 WARNING (MainThread) [homeassistant.config_entries] Config entry for unifi not ready yet. Retrying in 5 seconds.
2019-09-22 09:49:22 WARNING (MainThread) [homeassistant.setup] Setup of group is taking over 10 seconds.
2019-09-22 09:49:22 WARNING (MainThread) [homeassistant.setup] Setup of utility_meter is taking over 10 seconds.
2019-09-22 09:49:22 WARNING (MainThread) [homeassistant.components.binary_sensor] Setup of platform template is taking over 10 seconds.
2019-09-22 09:49:22 WARNING (MainThread) [homeassistant.components.weather] Setup of platform darksky is taking over 10 seconds.
2019-09-22 09:49:35 WARNING (MainThread) [homeassistant.setup] Setup of arlo is taking over 10 seconds.
2019-09-22 09:49:35 WARNING (MainThread) [homeassistant.components.media_player] Setup of platform samsungtv is taking over 10 seconds.
2019-09-22 09:49:35 WARNING (MainThread) [homeassistant.components.sensor] Setup of platform season is taking over 10 seconds.
2019-09-22 09:49:35 WARNING (MainThread) [homeassistant.components.sensor] Setup of platform template is taking over 10 seconds.
2019-09-22 09:49:35 WARNING (MainThread) [homeassistant.components.sensor] Setup of platform template is taking over 10 seconds.
2019-09-22 09:49:35 WARNING (MainThread) [homeassistant.components.sensor] Setup of platform template is taking over 10 seconds.
2019-09-22 09:49:35 WARNING (MainThread) [homeassistant.components.sensor] Setup of platform nmbs is taking over 10 seconds.
2019-09-22 09:49:35 WARNING (MainThread) [homeassistant.components.sensor] Setup of platform time_date is taking over 10 seconds.
2019-09-22 09:49:35 WARNING (MainThread) [homeassistant.components.sensor] Setup of platform template is taking over 10 seconds.
2019-09-22 09:49:35 WARNING (MainThread) [homeassistant.components.sensor] Setup of platform template is taking over 10 seconds.
2019-09-22 09:49:35 WARNING (MainThread) [homeassistant.components.sensor] Setup of platform systemmonitor is taking over 10 seconds.
2019-09-22 09:49:35 WARNING (MainThread) [homeassistant.components.sensor] Setup of platform nmbs is taking over 10 seconds.
2019-09-22 09:49:35 WARNING (MainThread) [homeassistant.components.sensor] Setup of platform ophaalkalender is taking over 10 seconds.
2019-09-22 09:49:35 WARNING (MainThread) [homeassistant.components.sensor] Setup of platform nmbs is taking over 10 seconds.
2019-09-22 09:49:35 WARNING (MainThread) [homeassistant.components.sensor] Setup of platform nmbs is taking over 10 seconds.
2019-09-22 09:49:49 ERROR (MainThread) [homeassistant.core] Error doing job: Unclosed client session
2019-09-22 09:50:06 WARNING (MainThread) [homeassistant.components.switch] Setup of platform alexa_media is taking over 10 seconds.
2019-09-22 09:50:09 WARNING (MainThread) [homeassistant.components.script] Script script.light_smappee_veranda_on_led already running.
2019-09-22 09:50:21 WARNING (MainThread) [homeassistant.components.script] Script script.notify_tracker_caro_thuis_ios_bert already running.
2019-09-22 09:50:25 ERROR (MainThread) [homeassistant.components.hue.sensor_base] Unable to reach bridge xxx.xxx.x.xx ()
2019-09-22 09:50:25 WARNING (MainThread) [homeassistant.components.light] Updating hue light took longer than the scheduled update interval 0:00:05
2019-09-22 09:50:28 ERROR (SyncWorker_10) [homeassistant.components.solaredge.sensor] Missing connections in power flow data

alandtse added a commit that referenced this issue Sep 22, 2019
fix: add retry logic to setup_entry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
alexapy Issue relates to the API bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants