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

Failed call to service configurator/configure . get #344

Closed
alandtse opened this issue Sep 5, 2019 · 10 comments · Fixed by #348
Closed

Failed call to service configurator/configure . get #344

alandtse opened this issue Sep 5, 2019 · 10 comments · Fixed by #348
Assignees
Labels
alexapy Issue relates to the API bug Something isn't working

Comments

@alandtse
Copy link
Owner

alandtse commented Sep 5, 2019

Describe the bug
Configurator can fail in the login in situations where Amazon attempts to reset cookies to - and that is then submitted back to Amazon. Because the cookies are invalid, Amazon then redirects to a page that says to enable javascript. There is a form which the _process_page function is pulling the action get. This is then submitted to and it fails because it's an invalid url.

This appears to only happen for the amazon.it domain.

To Reproduce
Steps to reproduce the behavior:

  1. Set domain to amazon.it
  2. Try to log in using configurator
  3. Error will display eventually

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
image

System details

  • Home-assistant (version): 0.98.1
  • Hassio (Yes/No): (Please note you may have to restart hassio 2-3 times to load the latest version of alexapy after an update. This looks like a HA bug).
  • alexa_media (version from const.py or HA startup): 2.1.0
  • alexapy (version from pip show alexapy or HA startup): 1.0.2

Logs

get
11:20 custom_components/alexa_media/__init__.py (ERROR) - message first occured at 11:17 and shows up 2 times

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 130, in handle_call_service
    connection.context(msg),
  File "/usr/src/homeassistant/homeassistant/core.py", line 1235, in async_call
    await asyncio.shield(self._execute_service(handler, service_call))
  File "/usr/src/homeassistant/homeassistant/core.py", line 1260, in _execute_service
    await handler.func(service_call)
  File "/usr/src/homeassistant/homeassistant/components/configurator/__init__.py", line 235, in async_handle_service_call
    await self.hass.async_add_job(callback, call.data.get(ATTR_FIELDS, {}))
  File "/config/custom_components/alexa_media/__init__.py", line 153, in configuration_callback
    login, callback_data)
  File "/config/custom_components/alexa_media/__init__.py", line 143, in setup_platform_callback
    await login.login(data=callback_data)
  File "/usr/local/lib/python3.7/site-packages/alexapy/alexalogin.py", line 306, in login
    headers=self._headers)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client.py", line 466, in _request
    ssl=ssl, proxy_headers=proxy_headers, traces=traces)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client_reqrep.py", line 286, in __init__
    self.update_host(url)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client_reqrep.py", line 340, in update_host
    raise InvalidURL(url)
aiohttp.client_exceptions.InvalidURL: get

Additional context
The root cause is the fact something is causing Amazon to invalidate the cookies in the login process. However, the code can probably be fixed to properly handle the page providing get so it restarts the login process.

https://community.home-assistant.io/t/echo-devices-alexa-as-media-player-testers-needed/58639/3123
https://community.home-assistant.io/t/echo-devices-alexa-as-media-player-testers-needed/58639/3141

@alandtse alandtse self-assigned this Sep 5, 2019
@alandtse alandtse added alexapy Issue relates to the API bug Something isn't working labels Sep 5, 2019
@alandtse
Copy link
Owner Author

alandtse commented Sep 5, 2019

Potential fix in alexapy here. Need an advanced tester who has this problem to try it. Otherwise, I'll handle it as soon as Amazon unthrottles me. ;)

@gericho
Copy link

gericho commented Sep 5, 2019

I can be you advanced tester, let me know

@alandtse
Copy link
Owner Author

alandtse commented Sep 5, 2019

@gericho thanks. I'll need to get logs from trying to login to a non-US domain.

  1. Ensure you have alexa_media 2.1.0 installed and working first.
  2. Replace your alexapy with the files in the PR on gitlab. Make backups if you need to.
  3. Rename your .pickle file.
  4. Enable logging for alexa_media and alexapy
  5. Try to login.

Hopefully it works successfully. If not, provide logs here or in a private gist.

@gericho
Copy link

gericho commented Sep 5, 2019

I cannot login, so I cannot pass step 1 (2.1.0 installed with HACS)

came up a banner with:
Failed to call service configurator/configure. Cannot be called from within the event loop

My configuration.yaml:

alexa_media:
  accounts:
    - email: !secret amazon_user
      password: !secret amazon_password
      url: amazon.it

PS: the 6 digit code come into the email normally

@alandtse
Copy link
Owner Author

alandtse commented Sep 5, 2019

Thanks. Sorry, I shouldn't have said "and working" for step 1. Can you go ahead and replace alexapy?

@gericho
Copy link

gericho commented Sep 5, 2019

I tried but maybe is over my talents...

I enabled logs as follow:

logger:      
  default: fatal
  logs:
    homeassistant.core: fatal
    custom_components.alexa_media: debug
    custom_components.alexapy: debug

So the alexa_media directory:

-rw-r--r-- 1 homeassistant homeassistant 33762 Sep  5 10:32 __init__.py
drwxr-xr-x 2 homeassistant homeassistant  4096 Sep  5 10:32 __pycache__
-rw-r--r-- 1 homeassistant homeassistant  8928 Sep  5 10:32 alarm_control_panel.py
drwxr-xr-x 2 homeassistant homeassistant  4096 Sep  5 20:36 alexa.py
-rw-r--r-- 1 homeassistant homeassistant  1314 Sep  5 10:32 const.py
-rw-r--r-- 1 homeassistant homeassistant  2217 Sep  5 10:32 helpers.py
-rw-r--r-- 1 homeassistant homeassistant   282 Sep  5 10:32 manifest.json
-rw-r--r-- 1 homeassistant homeassistant 31709 Sep  5 10:32 media_player.py
-rw-r--r-- 1 homeassistant homeassistant  7060 Sep  5 10:32 notify.py
-rw-r--r-- 1 homeassistant homeassistant   480 Sep  5 10:32 services.yaml
-rw-r--r-- 1 homeassistant homeassistant  8220 Sep  5 10:32 switch.py

and the alexa.py cloned from here

-rw-r--r-- 1 homeassistant homeassistant 38239 Sep  5 20:35 __init__.py
-rw-r--r-- 1 homeassistant homeassistant 38670 Sep  5 20:35 __version__.py
-rw-r--r-- 1 homeassistant homeassistant 38277 Sep  5 20:35 alexaapi.py
-rw-r--r-- 1 homeassistant homeassistant 38325 Sep  5 20:35 alexalogin.py
-rw-r--r-- 1 homeassistant homeassistant 38427 Sep  5 20:36 alexawebsocket.py

I get the same error as above, the 6 digits code comes into the email as before. Let me know where I can check the logs, thanks!

@alandtse
Copy link
Owner Author

alandtse commented Sep 5, 2019

One small change in your logger:

logger:      
  default: fatal
  logs:
    homeassistant.core: fatal
    custom_components.alexa_media: debug
    alexapy: debug

Your logs should be in the config directory under homeassistant.log. I'm at work so can't check specifically. The UI also has some logs in the Developer Tools section if you can't find the raw file.

@gericho
Copy link

gericho commented Sep 5, 2019

So the log is as follow:

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/websocket_api/commands.py", line 130, in handle_call_service
    connection.context(msg),
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/core.py", line 1235, in async_call
    await asyncio.shield(self._execute_service(handler, service_call))
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/core.py", line 1260, in _execute_service
    await handler.func(service_call)
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/configurator/__init__.py", line 235, in async_handle_service_call
    await self.hass.async_add_job(callback, call.data.get(ATTR_FIELDS, {}))
  File "/home/homeassistant/.homeassistant/custom_components/alexa_media/__init__.py", line 166, in configuration_callback
    login, callback_data)
  File "/home/homeassistant/.homeassistant/custom_components/alexa_media/__init__.py", line 158, in setup_platform_callback
    setup_platform_callback)
  File "/home/homeassistant/.homeassistant/custom_components/alexa_media/__init__.py", line 295, in test_login_status
    setup_platform_callback)
  File "/home/homeassistant/.homeassistant/custom_components/alexa_media/__init__.py", line 246, in request_configuration
    fields=[{'id': 'verificationcode', 'name': 'Verification Code'}]
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/configurator/__init__.py", line 93, in request_config
    hass.loop, ft.partial(async_request_config, hass, *args, **kwargs)
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/util/async_.py", line 201, in run_callback_threadsafe
    raise RuntimeError("Cannot be called from within the event loop")
RuntimeError: Cannot be called from within the event loop

and the home.assistant.log

@alandtse
Copy link
Owner Author

alandtse commented Sep 6, 2019

Thanks @gericho. Go ahead and restore your alexapy. I've been testing it tonight and that is probably not the solution. Trying a different angle now.

@alandtse
Copy link
Owner Author

alandtse commented Sep 8, 2019

Ok playing around more with this, it feels like only alexa.it has this problem and only if you have 2FA enabled. I have a new build I'll push that resolves the specific error but not the inability to use 2FA for amazon.it.

Workaround when I do the new release will be to disable 2FA to get the cookie and then reenable.

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

Successfully merging a pull request may close this issue.

2 participants