madmachinations / home-assistant-alexa-shopping-list

A custom component for Home Assistant which synchronises your Alexa Shopping List
GNU General Public License v3.0
32 stars 3 forks source link

login issue on amazon.it #27

Open raidolo opened 1 week ago

raidolo commented 1 week ago

Hi,

I just can't login using the client, I've tried different ways, running it inside the HA VM, on Windows WSL... no way...

I always get this error:

Alexa Shopping List Sync Client Console.

Attempting to connect to ws://192.168.1.30:4000
Connected successfully

Checking config
Config is invalid, performing setup...

Enter the base url you use to access Amazon (amazon.co.uk): amazon.it

Checking authentication
Server is not authenticated with Amazon, beginning login...

Enter your Amazon login details
Email address: XXXXXXXXXXXXXXXX      #REDACTED
Password: XXXXXXXXXXXXX  #REDACTED
Traceback (most recent call last):
  File "/home/raid/home-assistant-alexa-shopping-list/client/client.py", line 288, in <module>
    asyncio.run(client.run_console())
  File "/usr/lib/python3.9/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/home/raid/home-assistant-alexa-shopping-list/client/client.py", line 259, in run_console
    await self._check_server()
  File "/home/raid/home-assistant-alexa-shopping-list/client/client.py", line 84, in _check_server
    await self._setup_server_authentication()
  File "/home/raid/home-assistant-alexa-shopping-list/client/client.py", line 131, in _setup_server_authentication
    response = await self._send_command("login", email=email, password=password)
  File "/home/raid/home-assistant-alexa-shopping-list/client/client.py", line 39, in _send_command
    response = await websocket.recv()
  File "/home/raid/.local/lib/python3.9/site-packages/websockets/legacy/protocol.py", line 564, in recv
    await self.ensure_open()
  File "/home/raid/.local/lib/python3.9/site-packages/websockets/legacy/protocol.py", line 940, in ensure_open
    raise self.connection_closed_exc()
websockets.exceptions.ConnectionClosedError: received 1011 (internal error); then sent 1011 (internal error)

Is there any way to debug this? How?

Thanks!

raidolo commented 1 week ago

I've tried with the default docker, I've built my own with the PR changes to allow more than 13 items ( https://github.com/madmachinations/home-assistant-alexa-shopping-list/pull/23 ) but no matter what... It can't login. I've disabled the passkey, I've tried with MFA on and off, but I got no luck.

polmonta commented 1 week ago

Same error for amazon.es

Epicek1 commented 1 week ago

Same for me on amazon.co.uk. It reports the error before asking the login credentials.

stephenhenderson123 commented 1 week ago

I also have the same issue on amazon.co.uk, using the latest docker version. I do not passkey setup.

any help is greatly appreciated :) Thanks

Connected successfully

Checking config Config is invalid, performing setup...

Enter the base url you use to access Amazon (amazon.co.uk):

Checking authentication Server is not authenticated with Amazon, beginning login...

Enter your Amazon login details Email address: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Password: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Traceback (most recent call last): File "/data/configs/containers/ha-alexa-shopping-list-sync-01s2/home-assistant-alexa-shopping-list/client/client.py", line 288, in asyncio.run(client.run_console()) File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run return loop.run_until_complete(main) File "/usr/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete return future.result() File "/data/configs/containers/ha-alexa-shopping-list-sync-01s2/home-assistant-alexa-shopping-list/client/client.py", line 259, in run_console await self._check_server() File "/data/configs/containers/ha-alexa-shopping-list-sync-01s2/home-assistant-alexa-shopping-list/client/client.py", line 84, in _check_server await self._setup_server_authentication() File "/data/configs/containers/ha-alexa-shopping-list-sync-01s2/home-assistant-alexa-shopping-list/client/client.py", line 131, in _setup_server_authentication response = await self._send_command("login", email=email, password=password) File "/data/configs/containers/ha-alexa-shopping-list-sync-01s2/home-assistant-alexa-shopping-list/client/client.py", line 39, in _send_command response = await websocket.recv() File "/home/user2/.local/lib/python3.10/site-packages/websockets/legacy/protocol.py", line 564, in recv await self.ensure_open() File "/home/user2/.local/lib/python3.10/site-packages/websockets/legacy/protocol.py", line 940, in ensure_open raise self.connection_closed_exc() websockets.exceptions.ConnectionClosedError: received 1011 (internal error); then sent 1011 (internal error) user2@server02:/data/configs/containers/ha-alexa-shopping-list-sync-01s2/home-assistant-alexa-shopping-list/client$

docker logs:

2024-11-11T21:13:29.252741482Z connection handler failed 2024-11-11T21:13:29.252772882Z Traceback (most recent call last): 2024-11-11T21:13:29.252780825Z File "/usr/lib/python3.12/site-packages/websockets/legacy/server.py", line 245, in handler 2024-11-11T21:13:29.252786903Z await self.ws_handler(self) 2024-11-11T21:13:29.252792079Z File "/usr/lib/python3.12/site-packages/websockets/legacy/server.py", line 1188, in _ws_handler 2024-11-11T21:13:29.252797689Z return await cast( 2024-11-11T21:13:29.252806823Z ^^^^^^^^^^^ 2024-11-11T21:13:29.252812450Z File "/server/server.py", line 271, in _process_command 2024-11-11T21:13:29.252818004Z results = await _route_command(command, arguments) 2024-11-11T21:13:29.252823407Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-11-11T21:13:29.252828735Z File "/server/server.py", line 239, in _route_command 2024-11-11T21:13:29.252834349Z return await _cmd_login(arguments) 2024-11-11T21:13:29.252839331Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-11-11T21:13:29.252844652Z File "/server/server.py", line 147, in _cmd_login 2024-11-11T21:13:29.252849016Z instance.login(args['email'], args['password']) 2024-11-11T21:13:29.252853520Z File "/server/alexa.py", line 196, in login 2024-11-11T21:13:29.252858108Z self._handle_login() 2024-11-11T21:13:29.252862378Z File "/server/alexa.py", line 184, in _handle_login 2024-11-11T21:13:29.252867158Z self._handle_login_password_page() 2024-11-11T21:13:29.252871895Z File "/server/alexa.py", line 159, in _handle_login_password_page 2024-11-11T21:13:29.252877060Z self.driver.find_element(By.NAME, 'rememberMe').click() 2024-11-11T21:13:29.252881829Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-11-11T21:13:29.252887246Z File "/usr/lib/python3.12/site-packages/selenium/webdriver/remote/webdriver.py", line 748, in find_element 2024-11-11T21:13:29.252893154Z return self.execute(Command.FIND_ELEMENT, {"using": by, "value": value})["value"] 2024-11-11T21:13:29.252898817Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-11-11T21:13:29.252902941Z File "/usr/lib/python3.12/site-packages/selenium/webdriver/remote/webdriver.py", line 354, in execute 2024-11-11T21:13:29.252906899Z self.error_handler.check_response(response) 2024-11-11T21:13:29.252910778Z File "/usr/lib/python3.12/site-packages/selenium/webdriver/remote/errorhandler.py", line 229, in check_response 2024-11-11T21:13:29.252926475Z raise exception_class(message, screen, stacktrace) 2024-11-11T21:13:29.252930699Z selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[name="rememberMe"]"} 2024-11-11T21:13:29.252935266Z (Session info: chrome=129.0.6668.70); For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#no-such-element-exception 2024-11-11T21:13:29.252939675Z

raidolo commented 1 week ago

2024-11-11T21:13:29.252930699Z selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[name="rememberMe"]"}

It seems that it looks for the rememberMe selector, but I don't have it in my login page even when I use a standard browser. That could be the issue.

Do you guys have it in your login page? (Using a standard browser of course)

stephenhenderson123 commented 1 week ago

Using Chrome in incognito mode I do not have a "remember me" option. The closest I have is "Don't require OTP on this device"

image

raidolo commented 1 week ago

Using Chrome in incognito mode I do not have a "remember me" option. The closest I have is "Don't require OTP on this device"

Same....

raidolo commented 1 week ago

@stephenhenderson123 @polmonta @Epicek1 @madmachinations Ok guys, I've just commented the line 159 in the alexa.py, the one that refers to the "rememberMe" button, and now it's working!! I got authenticated and I was able to retrieve the list at least via the command line....

polmonta commented 1 week ago

@stephenhenderson123 @polmonta @Epicek1 @madmachinations Ok guys, I've just commented the line 159 in the alexa.py, the one that refers to the "rememberMe" button, and now it's working!! I got authenticated and I was able to retrieve the list at least via the command line....

If I am using HASS OS as the server (with the HASS Addon), I need to change the alexa.py file within HomeAssistant right? How is it possible to access that file? I tried going to add-ons and addons_config, but nothing is showing up there.

NinjaDinoMonkey commented 1 week ago

@polmonta let me know if you find it. My HASS OS is looking at this repository (through HACS) for alexa.py and I cant find where its downloaded to the system

raidolo commented 1 week ago

If I am using HASS OS as the server (with the HASS Addon), I need to change the alexa.py file within HomeAssistant right? How is it possible to access that file? I tried going to add-ons and addons_config, but nothing is showing up there.

Nope, I believe the alexa.py exists only in the server part of this repository, not the HA addon. I didn't install the addon yet cause I had the issue with the server, but I'll let you know when I'll do it.

How do you run the server? Docker? You need to rebuild the docker container in that case. I've used the alexa.py file in this Pull Request and I've commented the "remindMe" line, then I've built the container using the command inside the "server" directory:

sudo docker build --rm -f "Dockerfile" -t ha-shopping-list-sync:latest .

The alexa.py file is this: https://github.com/madmachinations/home-assistant-alexa-shopping-list/blob/c3450fe624a46f681ce2a87fda6df15c1c2e4dae/server/alexa.py

madmachinations commented 1 week ago

If you're using the hass add on, the way that works is:

So it sounds like this fix needs to be made more elaborate, possibly checking to see if it can find a remember me check box, and if so tick it, and if not, ignore it and carry on.

Sorry for my general absence, I'm being absolutely hammered at work for big project deadlines lately.

I don't think there is any way to hack your way around that fix temporarily on a hass os add-on deployment. The script is already in memory, so even going into the container and editing will do nothing. If the server is restarted to reload the changes, the container will refresh and the edits will be undone.

So it will have to be merged into master and new containers deployed.

raidolo commented 1 week ago

If you're using the hass add on, the way that works is:

  • Code in master changes

  • CI builds and pushes out new docker containers with a date tag, and updates the latest tagged image to the new version

  • (Re)install the hass add on, which just pulls down whatever the latest build of the docker container is.

So it sounds like this fix needs to be made more elaborate, possibly checking to see if it can find a remember me check box, and if so tick it, and if not, ignore it and carry on.

Sorry for my general absence, I'm being absolutely hammered at work for big project deadlines lately.

I don't think there is any way to hack your way around that fix temporarily on a hass os add-on deployment. The script is already in memory, so even going into the container and editing will do nothing. If the server is restarted to reload the changes, the container will refresh and the edits will be undone.

So it will have to be merged into master and new containers deployed.

But the HA Addon includes the server?

raidolo commented 1 week ago

Oh now I see, I've missed the HA server addon! I prefer to build it from the source anyway, to make these changes... I'll try the custom component soon. Anyway thanks for all this!

Epicek1 commented 1 week ago

@madmachinations So if I use the add-on, there is no real workaround, just wait until the code is corrected and reinstall the add-on? I tried reinstalling and it went one step further (asking for the login credentials), than giving the same error message.

polmonta commented 1 week ago

Seems like there is some progress with the last update! I was able to authenticate successfully, but when I try to execute a command or either open the console again, the following error comes up:

Alexa Shopping List Sync Client Console.

Attempting to connect to ws://192.168.0.230:4000
Traceback (most recent call last):
  File "/Users/XXXX/Downloads/home-assistant-alexa-shopping-list-main/client/my_client_env/lib/python3.13/site-packages/websockets/legacy/client.py", line 655, in __await_impl__
    await protocol.handshake(
    ...<5 lines>...
    )
  File "/Users/XXXX/Downloads/home-assistant-alexa-shopping-list-main/client/my_client_env/lib/python3.13/site-packages/websockets/legacy/client.py", line 315, in handshake
    status_code, response_headers = await self.read_http_response()
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/XXXX/Downloads/home-assistant-alexa-shopping-list-main/client/my_client_env/lib/python3.13/site-packages/websockets/legacy/client.py", line 135, in read_http_response
    status_code, reason, headers = await read_response(self.reader)
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/XXXX/Downloads/home-assistant-alexa-shopping-list-main/client/my_client_env/lib/python3.13/site-packages/websockets/legacy/http.py", line 120, in read_response
    status_line = await read_line(stream)
                  ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/XXXX/Downloads/home-assistant-alexa-shopping-list-main/client/my_client_env/lib/python3.13/site-packages/websockets/legacy/http.py", line 194, in read_line
    line = await stream.readline()
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.13/3.13.0_1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/streams.py", line 562, in readline
    line = await self.readuntil(sep)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.13/3.13.0_1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/streams.py", line 677, in readuntil
    await self._wait_for_data('readuntil')
  File "/opt/homebrew/Cellar/python@3.13/3.13.0_1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/streams.py", line 539, in _wait_for_data
    await self._waiter
asyncio.exceptions.CancelledError

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

Traceback (most recent call last):
  File "/Users/XXXX/Downloads/home-assistant-alexa-shopping-list-main/client/client.py", line 288, in <module>
    asyncio.run(client.run_console())
    ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.13/3.13.0_1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/runners.py", line 194, in run
    return runner.run(main)
           ~~~~~~~~~~^^^^^^
  File "/opt/homebrew/Cellar/python@3.13/3.13.0_1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/opt/homebrew/Cellar/python@3.13/3.13.0_1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/base_events.py", line 721, in run_until_complete
    return future.result()
           ~~~~~~~~~~~~~^^
  File "/Users/XXXX/Downloads/home-assistant-alexa-shopping-list-main/client/client.py", line 259, in run_console
    await self._check_server()
  File "/Users/XXXX/Downloads/home-assistant-alexa-shopping-list-main/client/client.py", line 67, in _check_server
    connected = await self._ping_server()
                ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/XXXX/Downloads/home-assistant-alexa-shopping-list-main/client/client.py", line 89, in _ping_server
    response = await self._send_command("ping")
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/XXXX/Downloads/home-assistant-alexa-shopping-list-main/client/client.py", line 31, in _send_command
    async with websockets.connect(self.uri) as websocket:
               ~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/Users/XXXX/Downloads/home-assistant-alexa-shopping-list-main/client/my_client_env/lib/python3.13/site-packages/websockets/legacy/client.py", line 634, in __aenter__
    return await self
           ^^^^^^^^^^
  File "/Users/XXXX/Downloads/home-assistant-alexa-shopping-list-main/client/my_client_env/lib/python3.13/site-packages/websockets/legacy/client.py", line 651, in __await_impl__
    async with asyncio_timeout(self.open_timeout):
               ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.13/3.13.0_1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/timeouts.py", line 116, in __aexit__
    raise TimeoutError from exc_val
TimeoutError

Also, I was able to set up the Integration correctly, but the list's status is 'Unknown':

Screenshot 2024-11-12 at 21 29 31
polmonta commented 1 week ago

The same error now appeared again after the "Checking config" message.

raidolo commented 1 week ago

It works!!!! I've installed the custom component and I'm able to sync the shopping list. It works both ways it seems. The only dowwnside is that when it syncs I can distinclty hear the fan of my mini pc ramping up, chromium is a bit of a heavy load to do this kind of job. I'll test it more, the only annoying thing is that going this way we can't sync the list frequently... but anyway... GREAT JOB! Thanks!

madmachinations commented 1 week ago

@madmachinations So if I use the add-on, there is no real workaround, just wait until the code is corrected and reinstall the add-on? I tried reinstalling and it went one step further (asking for the login credentials), than giving the same error message.

Ya, if you're using the add-on, you're using the pre-build docker container and that can't be tweaked on-the-fly. So any changes have to be made to the code, then a new container gets built, then you run the new version.

madmachinations commented 1 week ago

It works!!!! I've installed the custom component and I'm able to sync the shopping list. It works both ways it seems. The only dowwnside is that when it syncs I can distinclty hear the fan of my mini pc ramping up, chromium is a bit of a heavy load to do this kind of job. I'll test it more, the only annoying thing is that going this way we can't sync the list frequently... but anyway... GREAT JOB! Thanks!

Congrats! Glad it's working for you 😆

raidolo commented 1 week ago

Congrats! Glad it's working for you 😆

Great! I've seen you have merged the pull request for the "more than 13 items" bug.... could you push the creation of the docker container? Also, i've just commented the remeberMe line netirely and it just works... could you please code an "if" to check if the button is present or not? I'd like to test the HA addon as well, cause I'm running supervised and they don't like it when you run containers outside HA addons... I've built my own container at the moment :)

raidolo commented 1 week ago

Umh.... I've seen your merge but then the alexa.py in the main brach was not updated, I got this while navigating in the merged commit:

image

Do you know why?

Thanks!