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

Relogin required after reboot if 2 differents amazon accounts are setup #1098

Closed
somar05 opened this issue Jan 9, 2021 · 11 comments
Closed

Comments

@somar05
Copy link

somar05 commented Jan 9, 2021

Describe the bug
Similar behavior than v.3.4.7 with issue #1082
With one account it seems that there is no problem. Then, when second account is added, it seems to work correctly. However, after reboot, relogin is required for the first account. No matter how many times you do it, always is required after reboot. As comment, it looks that a separate login is required per alexa device take into account the relogin bellow screenshot

To Reproduce
Steps to reproduce the behavior:

  1. Integrations deleted
  2. Added v.3.4.8
  3. Reboot
  4. Added 1st account (2fa) succesfully
  5. Reboot
  6. Testing ok
  7. Added second account
  8. Testing ok
  9. Reboot
  10. Errors logged and relogin required
  11. Relogin ok
  12. Reboot to test
  13. Back to step 10 (loop)

Expected behavior
Credentials stored properly for more than one account

Screenshots
image

System details

  • Home-assistant (version): 2020.12.7
  • Hassio (Yes/No): Yes
  • alexa_media (version from const.py or HA startup): 3.4.8
  • alexapy (version from pip show alexapy or HA startup):
  • Amazon 2FA is enabled (y/n). We will not debug login issues if unanswered: Yes

Logs
Logger: alexapy.alexalogin Source: /usr/local/lib/python3.8/site-packages/alexapy/alexalogin.py:650 First occurred: 8:44:56 (1 occurrences) Last logged: 8:44:56 No access token found; falling back to credential login instead of oauth.

alexaapi.send_announcement((<alexapy.alexaapi.AlexaAPI object at 0x6786ace8>, 'Test'), {'customer_id': 'xxxx', 'targets': ['xxxx'], 'title': 'Home Assistant', 'method': 'all', 'queue_delay': 1.5}): An error occured accessing AlexaAPI: An exception of type AlexapyLoginError occurred. Arguments: ('Unauthorized',)

Logger: alexapy.helpers Source: /usr/local/lib/python3.8/site-packages/alexapy/helpers.py:153 First occurred: 8:51:14 (1 occurrences) Last logged: 8:51:14 alexaapi.get_notifications((<alexapy.alexalogin.AlexaLogin object at 0x70d539e8>,), {}): A login error occured: An exception of type JSONDecodeError occurred. Arguments: ('Expecting value: line 1 column 1 (char 0)',)

Logger: alexapy.helpers Source: /usr/local/lib/python3.8/site-packages/alexapy/helpers.py:187 First occurred: 8:51:14 (2 occurrences) Last logged: 8:51:14 alexaapi.get_activities((<alexapy.alexalogin.AlexaLogin object at 0x70d539e8>, 10), {}): An error occured accessing AlexaAPI: An exception of type AlexapyLoginError occurred. Arguments: ('Login error detected; not contacting API',) alexaapi.get_last_device_serial((<alexapy.alexalogin.AlexaLogin object at 0x70d539e8>,), {}): An error occured accessing AlexaAPI: An exception of type AlexapyLoginError occurred. Arguments: ('Login error detected; not contacting API',)

Logger: aiohttp.websocket Source: /usr/local/lib/python3.8/site-packages/alexapy/aiohttp/http_websocket.py:599 First occurred: 8:51:11 (1 occurrences) Last logged: 8:51:11 websocket connection is closing.

Logger: alexapy.helpers Source: /usr/local/lib/python3.8/site-packages/alexapy/helpers.py:187 First occurred: 8:51:14 (25 occurrences) Last logged: 8:52:10 alexaapi.get_state((<alexapy.alexaapi.AlexaAPI object at 0x68eb3400>,), {}): An error occured accessing AlexaAPI: An exception of type AlexapyLoginError occurred. Arguments: ('Login error detected; not contacting API',)

Alexa Media Reauthentication Required Reauthenticate [email protected] on the Integrations page. Relogin required after 0:01:01.411918 and 7 api calls.

Additional context
Domain ".es"
Rolling back to v3.4.1 and working properly with two accounts

@alandtse
Copy link
Owner

alandtse commented Jan 9, 2021

Thanks. I've determined this is caused by a rate issue with hitting the Amazon servers too much at once and have a solution. However, the logic for connections wasn't changed in since 3.4.1 so I'm not sure how you're not seeing the same issue in 3.4.1.

@alandtse
Copy link
Owner

alandtse commented Jan 9, 2021

Can you please try the PR #1100 to see if it resolves the issue?

@somar05
Copy link
Author

somar05 commented Jan 9, 2021

Sure, but please, could you refresh me how procedure to test the PR? I remember that I have done at others times, but but I can't remember it now

@alandtse
Copy link
Owner

alandtse commented Jan 9, 2021

@somar05
Copy link
Author

somar05 commented Jan 9, 2021

No luck. Similar behavior I guess. Steps taken:

  1. Remove integrations
  2. Update to 3.4.8 and __init__.py replaced
  3. Reboot
  4. Added first account with no problem (2FA)
  5. Reboot to check working properly: working
  6. Added second acount with no problem (2FA)
  7. Reboot
  8. Relogin required for 1st account
  9. Relogin and second 2FA dialog appears, but login done properly and test ok
  10. Reboot
  11. Relogin again as step 8 (loop)

Some logs to try to help. These after the relogin request at step 8:

Reauthenticate [email protected] on the Integrations page. Relogin required after 0:00:47.271220 and 12 api calls.

Logger: alexapy.helpers Source: /usr/local/lib/python3.8/site-packages/alexapy/helpers.py:153 First occurred: 11:53:41 (5 occurrences) Last logged: 11:53:42 alexaapi.get_devices((<alexapy.alexalogin.AlexaLogin object at 0x6ffe1e68>,), {}): A login error occured: An exception of type JSONDecodeError occurred. Arguments: ('Expecting value: line 1 column 1 (char 0)',) alexaapi.get_state((<alexapy.alexaapi.AlexaAPI object at 0x68411b98>,), {}): A login error occured: An exception of type JSONDecodeError occurred. Arguments: ('Expecting value: line 1 column 1 (char 0)',) alexaapi.get_device_preferences((<alexapy.alexalogin.AlexaLogin object at 0x6ffe1e68>,), {}): A login error occured: An exception of type JSONDecodeError occurred. Arguments: ('Expecting value: line 1 column 1 (char 0)',) alexaapi.get_bluetooth((<alexapy.alexalogin.AlexaLogin object at 0x6ffe1e68>,), {}): A login error occured: An exception of type JSONDecodeError occurred. Arguments: ('Expecting value: line 1 column 1 (char 0)',) alexaapi.get_dnd_state((<alexapy.alexalogin.AlexaLogin object at 0x6ffe1e68>,), {}): A login error occured: An exception of type JSONDecodeError occurred. Arguments: ('Expecting value: line 1 column 1 (char 0)',)

Logger: homeassistant.components.media_player Source: custom_components/alexa_media/media_player.py:559 Integration: Reproductor multimedia (documentation, issues) First occurred: 11:53:41 (1 occurrences) Last logged: 11:53:41 Error while setting up alexa_media platform for media_player Traceback (most recent call last): File "/usr/local/lib/python3.8/site-packages/alexapy/helpers.py", line 141, in wrapper return await func(*args, **kwargs) File "/usr/local/lib/python3.8/site-packages/alexapy/alexaapi.py", line 1061, in get_state return await response.json(content_type=None) if response else None File "/usr/local/lib/python3.8/site-packages/alexapy/aiohttp/client_reqrep.py", line 1095, in json return loads(stripped.decode(encoding)) File "/usr/local/lib/python3.8/json/__init__.py", line 357, in loads return _default_decoder.decode(s) File "/usr/local/lib/python3.8/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/local/lib/python3.8/json/decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 199, in _async_setup_platform await asyncio.shield(task) File "/config/custom_components/alexa_media/media_player.py", line 120, in async_setup_entry if await async_setup_platform( File "/config/custom_components/alexa_media/media_player.py", line 101, in async_setup_platform await alexa_client.init(device) File "/config/custom_components/alexa_media/media_player.py", line 218, in init await self.refresh(device) File "/config/custom_components/alexa_media/helpers.py", line 159, in _catch_login_errors result = await func(*args, **kwargs) File "/config/custom_components/alexa_media/media_player.py", line 559, in refresh session = await self.alexa_api.get_state() File "/usr/local/lib/python3.8/site-packages/alexapy/helpers.py", line 161, in wrapper login.status["login_successful"] = False AttributeError: 'NoneType' object has no attribute 'status'

And this one after relogin request at step 9:
Logger: homeassistant.config_entries Source: helpers/entity_component.py:155 First occurred: 11:57:07 (1 occurrences) Last logged: 11:57:07 Error setting up entry [email protected] - amazon.es for media_player Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/config_entries.py", line 236, in async_setup result = await component.async_setup_entry(hass, self) # type: ignore File "/usr/src/homeassistant/homeassistant/components/media_player/__init__.py", line 345, in async_setup_entry return await hass.data[DOMAIN].async_setup_entry(entry) File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 155, in async_setup_entry raise ValueError("Config entry has already been setup!") ValueError: Config entry has already been setup!

If a further test can be done, just tell me.

@somar05
Copy link
Author

somar05 commented Jan 9, 2021

Just a comment... The strange thing is that the relogin is required always for the 1st account and only if the second one is added. If the second acount is not added, then the first one works like a charm. And with 3.4.1 these not happens, and looks like the login procedure is faster, but this last could be only an assessment from me, no way to confirm.

@alandtse
Copy link
Owner

alandtse commented Jan 9, 2021

Can you provide startup logs showing the disconnect please? That's the part where I can see how many api calls are happening at the same time and causing the behavior. You should see both accounts setting up one after the other instead of interspersed. If it's interspersed, then you may not have replaced the __init__ file.

@somar05
Copy link
Author

somar05 commented Jan 9, 2021

I suppose that I have to set the debug mode or something similar to take the start up log? If yes, I remember I have to add something like this in the configuration file. It is still applicable?

 logger:
   default: warning
   logs:
     custom_components.alexa_media: debug
     alexapy: debug

@somar05
Copy link
Author

somar05 commented Jan 9, 2021

The debug log is huge, so not sure if I can find the lines with relevant information. Anyway, I paste some lines that have caught my attention. If the complete log is relevant to investigate, let me know how I can send you, because is very large and also contain sensitive information to be paste here.

2021-01-09 13:53:47 WARNING (MainThread) [alexapy.alexalogin] No access token found; falling back to credential login instead of oauth.

2021-01-09 13:53:54 DEBUG (MainThread) [alexapy.alexalogin] WARNING: Detected missing params: ['encryptedPasswordExpected']

@alandtse
Copy link
Owner

alandtse commented Jan 9, 2021

Yes, I do need to see the startup right before it detects an issue. I believe you've messaged me on Discord before. alandtse#5464. I've also updated the PR with another version.
https://raw.githubusercontent.com/custom-components/alexa_media_player/8320df8eafae2d718348a701058848bc15949f73/custom_components/alexa_media/__init__.py

alandtse added a commit that referenced this issue Jan 11, 2021
@alandtse alandtse reopened this Jan 12, 2021
@LaskaBozzolo
Copy link

I can confirm this issue: I have two account, at every reboot I need to relogin. But this happens sometimes just like that, in normal use. I just login in homeassistant and I see alexa media player needs reauthentication.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants