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

Server thinks it's authenticated when it isn't after a period of inactivity #16

Closed madmachinations closed 1 month ago

madmachinations commented 1 month ago

Server thinks it's authenticated when it isn't after a period of inactivity

mekki1986 commented 1 month ago

I uninstalled the server that I had installed via hacs and removed the folders in custom_components and client. I reinstalled it but it doesn't ask me to authenticate. So there are other files that maintain it, but I can't find them. Where can they be?

madmachinations commented 1 month ago

I uninstalled the server that I had installed via hacs and removed the folders in custom_components and client. I reinstalled it but it doesn't ask me to authenticate. So there are other files that maintain it, but I can't find them. Where can they be?

I'm not sure where HASS stores them, but when you install the HASS Add-on it tells HASS it wants a folder somewhere that it can keep permanent files.

A quick google tells me there should be a folder, probably called alexa_shopping_list, in here:

/mnt/data/supervisor/addons/data/

Delete that folder and start up the server again, and it should be a fresh install from that point

mekki1986 commented 1 month ago

I'm sorry, I can't find the file. I tried in every way, from terminal, with samba with file editor, but I don't have any folders with that name. Unfortunately I will have to give up the integration. Thanks anyway for your work

KiraPC commented 1 month ago

When you get the token from the browser, can you open it and check the expiration date?

moryoav commented 1 month ago

I'm having a similar problem, or similar to the other issue reported here, I'm not sure. I did step #2 in the guide, and used the amazon.uk server. I then realized (it should be clarified in the readme) that Amazon has separate shopping lists for every site, and I was using the .com one for my lists. So my .uk shopping list was empty (maybe that's an issue users are experiencing not realizing this is the case). I then had no way to change my credentials to the .com site, or at least I couldn't figure out how to do it. So I uninstalled the server and re-installed it, thinking I could now do step #2 again and re-do the authentication process. However now I get the situation where it tells me (I was not given the option to re-authenticate, contrary to what I thought would happen):

Checking config
Config is valid

Checking authentication
Server is authenticated

And then when I do "list" it tells me ERROR: Not authenticated.

I cannot find where the server stores the data files in Home Assistant (Installed through HACS). It would be great if among the other command line options, I would have a command to "reauthenticate" which will allow me to just do it again.

madmachinations commented 1 month ago

I'm having a similar problem, or similar to the other issue reported here, I'm not sure. I did step #2 in the guide, and used the amazon.uk server. I then realized (it should be clarified in the readme) that Amazon has separate shopping lists for every site, and I was using the .com one for my lists. So my .uk shopping list was empty (maybe that's an issue users are experiencing not realizing this is the case). I then had no way to change my credentials to the .com site, or at least I couldn't figure out how to do it. So I uninstalled the server and re-installed it, thinking I could now do step #2 again and re-do the authentication process. However now I get the situation where it tells me (I was not given the option to re-authenticate, contrary to what I thought would happen):

Checking config
Config is valid

Checking authentication
Server is authenticated

And then when I do "list" it tells me ERROR: Not authenticated.

I cannot find where the server stores the data files in Home Assistant (Installed through HACS). It would be great if among the other command line options, I would have a command to "reauthenticate" which will allow me to just do it again.

I will add a command to reset the server config, in the mean time:

Did you mean you installed through HASS or through HACS? Because HACS doesn't have the server, it only has the HA component, and that install method is completely untested. So I assume you mean HASS?

If that is the case, on your HASS OS device, please can you look in:

usr/share/hassio/addons/

and see if there is an alexa_shopping_list, or similar, folder in there?

If there is, is there a data folder inside that? If so, delete everything in the data folder and restart the server.

moryoav commented 1 month ago

Did you mean you installed through HASS or through HACS? Because HACS doesn't have the server, it only has the HA component, and that install method is completely untested. So I assume you mean HASS?

If that is the case, on your HASS OS device, please can you look in:

usr/share/hassio/addons/

and see if there is an alexa_shopping_list, or similar, folder in there?

If there is, is there a data folder inside that? If so, delete everything in the data folder and restart the server.

Yeah, my mistake, I meant I installed the addon regularly as HASS addon (as the readme suggested, from https://gitlab.com/home-assistant-components/hass-addons) And yes, I'm on Home Assistant OS device. However, in /usr/share I have no hassio folder. If I do "find / -name "addons" I find two such folders (one /root/addons and the other /addons), they're both empty.

madmachinations commented 1 month ago

Did you mean you installed through HASS or through HACS? Because HACS doesn't have the server, it only has the HA component, and that install method is completely untested. So I assume you mean HASS? If that is the case, on your HASS OS device, please can you look in: usr/share/hassio/addons/ and see if there is an alexa_shopping_list, or similar, folder in there? If there is, is there a data folder inside that? If so, delete everything in the data folder and restart the server.

Yeah, my mistake, I meant I installed the addon regularly as HASS addon (as the readme suggested, from https://gitlab.com/home-assistant-components/hass-addons) And yes, I'm on Home Assistant OS device. However, in /usr/share I have no hassio folder. If I do "find / -name "addons" I find two such folders (one /root/addons and the other /addons), they're both empty.

Hmmm, I'm sorry I have no idea where HASS OS puts addon persistent storage. The documentation for it is pretty useless in that regard tbh. And I don't have a HASS OS device to have a look around and see, so I'm blind. I will add a reset command this evening

moryoav commented 1 month ago

So I decided to go another route, and I installed the server as a docker container from DockerHub, on a different computer. Now I have the folders that I mounted when setting it up and I have access to the /config/ folder. Now, back to step #2, I now run "python3 client.py " with the different IP now... and...

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

Checking config
Config is valid

Checking authentication
Server is authenticated

How did it authenticate on this new server if I didn't define anything?

And then when doing "list":


> list
Traceback (most recent call last):
  File "C:\Users\Yoav\Downloads\alexa-shopping-list\client\client.py", line 272, in <module>
    asyncio.run(client.run_console())
  File "C:\Program Files\Python310\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "C:\Program Files\Python310\lib\asyncio\base_events.py", line 646, in run_until_complete
    return future.result()
  File "C:\Users\Yoav\Downloads\alexa-shopping-list\client\client.py", line 258, in run_console
    keep_running = await self._handle_commands(command, arguments)
  File "C:\Users\Yoav\Downloads\alexa-shopping-list\client\client.py", line 223, in _handle_commands
    await self._cmd_get_shopping_list()
  File "C:\Users\Yoav\Downloads\alexa-shopping-list\client\client.py", line 175, in _cmd_get_shopping_list
    response = await self._send_command("get_list")
  File "C:\Users\Yoav\Downloads\alexa-shopping-list\client\client.py", line 39, in _send_command
    response = await websocket.recv()
  File "C:\Users\Yoav\AppData\Roaming\Python\Python310\site-packages\websockets\legacy\protocol.py", line 564, in recv
    await self.ensure_open()
  File "C:\Users\Yoav\AppData\Roaming\Python\Python310\site-packages\websockets\legacy\protocol.py", line 931, in ensure_open
    raise self.connection_closed_exc()
websockets.exceptions.ConnectionClosedError: received 1011 (internal error); then sent 1011 (internal error)
moryoav commented 1 month ago

And I'll just add that I saw in the config folder two files, config.json and a cookies file, I deleted both files and restarted the server, and now only the config.json gets created and not the cookies file, for some reason. And I get the error above. Maybe this is no longer relevant to this github issue, not sure anymore.

madmachinations commented 1 month ago

And I'll just add that I saw in the config folder two files, config.json and a cookies file, I deleted both files and restarted the server, and now only the config.json gets created and not the cookies file, for some reason. And I get the error above. Maybe this is no longer relevant to this github issue, not sure anymore.

So I can't be sure, but it sounds like you still had the client running while you were deleting, and after having deleted, the server's file cache.

The client only asks the server if it has it's shit together and can do the do when it first opens and makes a connection with the server. So if you killed the client and re-ran it, it should have launched into the first run setup again, if you had deleted the server's cache and restarted it.

A new version of the server container is on docker hub now, if you update your server to this version and you download the new client from this repository, you should have access to a reset command.

This reset command just tells the server to delete it's file cache, and it causes the client to run the setup process again having done so.