alandtse / alexa_media_player

This is a custom component to allow control of Amazon Alexa devices in Home Assistant using the unofficial Alexa API.
Apache License 2.0
1.5k stars 286 forks source link

Not able to Log In. Unknown Error Occurred #2393

Closed Techposts closed 2 months ago

Techposts commented 2 months ago

IMPORTANT: Please search the issues, including closed issues, and the FAQ before opening a new issue. The template is mandatory; failure to use it will result in issue closure.

Describe the bug

Enabled the 2FA. Added the Google Authenticator App. The integration is showing the OTP which matches the OTP on the Google Authenticator but when I click SUBMIT, it says Unknow Error occurred.

Tried Amaozn.com and Amazon.in

chrome_nD1PMEjFbN chrome_4ncBT5GfUR chrome_UEic2XZkDj chrome_sjbFghY6Py

Logs No logs generated for this as integration is failing. Alexa Media Player v4.12.4

(https://github.com/alandtse/alexa_media_player/wiki/FAQ#how-do-i-enable-debug-logging-for-the-component).

Mally2004uk commented 2 months ago

My workaround, install with hacs Version 4.12.0 and login, After successfull login, Update to current version

I have just tried this and i still get unknown error when trying to login

danielbrunt57 commented 2 months ago

@Mally2004uk Since you've not provided alexa_media & alexapy debug logs, I'm only guessing that you should start with whether your Amazon account works outside of this integration while using the email, password & TOTP/OTP secret that you've specified in the integration. The integration is now working with AMP 4.12.4 plus the files from the latest PR #2398...

joeuser000 commented 2 months ago

I never get far enough to generate the OTP code in the integration. It fails before that. I'd be happy to post the logs that I have. I posted a fragment of the logs that show an error with the URL in the code. see previous post.

thx

On Mon, Aug 5, 2024 at 6:12 PM Daniel @.***> wrote:

@Mally2004uk https://github.com/Mally2004uk Since you've not provided alexa_media & alexapy debug logs, I'm only guessing that you should start with whether your Amazon account works outside of this integration while using the email, password & TOTP/OTP secret that you've specified in the integration. The integration is now working with AMP 4.12.4 plus the files from the latest PR #2398 https://github.com/alandtse/alexa_media_player/pull/2398/files...

— Reply to this email directly, view it on GitHub https://github.com/alandtse/alexa_media_player/issues/2393#issuecomment-2270071871, or unsubscribe https://github.com/notifications/unsubscribe-auth/BJRUDT5QYW6IYXNNFIXRAHTZQABE7AVCNFSM6AAAAABL5YNVU6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENZQGA3TCOBXGE . You are receiving this because you commented.Message ID: @.***>

joeuser000 commented 2 months ago

Here the log entries for the latest attempt. thanks. I did verify the OTP code btw....sorry for the confusion.

File "/config/custom_components/alexa_media/config_flow.py", line 551, in async_step_totp_register return await self.async_step_start_proxy(user_input) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/alexa_media/config_flow.py", line 358, in async_step_start_proxy str(URL(self.config.get(CONF_HASS_URL)).with_path(AUTH_PROXY_PATH)), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/yarl/_url.py", line 179, in __new__ raise TypeError("Constructor parameter should be str") TypeError: Constructor parameter should be str simdo01-desktop:/config# tail 300 home-assistant.log tail: can't open '300': No such file or directory ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/alexa_media/config_flow.py", line 551, in async_step_totp_register return await self.async_step_start_proxy(user_input) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/alexa_media/config_flow.py", line 358, in async_step_start_proxy str(URL(self.config.get(CONF_HASS_URL)).with_path(AUTH_PROXY_PATH)), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/yarl/_url.py", line 179, in __new__ raise TypeError("Constructor parameter should be str") TypeError: Constructor parameter should be str

danielbrunt57 commented 2 months ago

With AMP 4.12.4 + the files from PR#2398?

joeuser000 commented 2 months ago

installed your version. HA CORE log... 2024-08-05 19:02:25.307 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration alexa_media which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant 2024-08-05 19:02:29.041 INFO (MainThread) [homeassistant.bootstrap] Setting up stage 2: {'select', 'nest', 'search', 'input_text', 'assist_pipeline', 'stt', 'script', 'input_number', 'weatherflow', 'scheduler', 'wake_word', 'radio_browser', 'local_calendar', 'history', 'brother', 'ibeacon', 'energy', 'blueprint', 'tts', 'spook', 'zwave_js', 'alexa_media', 'counter', 'onboarding', 'mqtt', 'input_select', 'system_health', 'weatherflow_forecast', 'nodered', 'application_credentials', 'tag', 'cast', 'tplink', 'sun', 'file_upload', 'ffmpeg', 'default_config', 'shopping_list', 'sensor', 'number', 'backup', 'hacs', 'intent', 'input_boolean', 'automation', 'met', 'logbook', 'my', 'input_datetime', 'google_translate', 'config', 'ipp', 'bluetooth_adapters', 'mobile_app', 'androidtv_remote', 'input_button', 'zone', 'image_upload', 'persistent_notification', 'person', 'esphome', 'diagnostics', 'scene', 'hardware', 'media_source', 'conversation', 'analytics', 'homeassistant_alerts', 'trace', 'map', 'schedule', 'timer', 'sonos', 'stream', 'device_automation', 'lovelace', 'version', 'homeassistant'} 2024-08-05 19:02:37.479 INFO (MainThread) [homeassistant.setup] Setting up alexa_media 2024-08-05 19:02:37.486 ERROR (MainThread) [homeassistant.setup] Error during setup of component alexa_media File "/config/custom_components/alexa_media/__init__.py", line 136, in async_setup 2024-08-05 19:02:37.501 INFO (MainThread) [homeassistant.setup] Setup of domain alexa_media took 0.01 seconds 2024-08-05 19:12:48.045 DEBUG (MainThread) [custom_components.alexa_media.config_flow] Creating new login 2024-08-05 19:12:48.046 DEBUG (MainThread) [custom_components.alexa_media.helpers] j***************l@g*******m: Returning uuid {'uuid': '2af6373ab2c04f1a2e651704c949039f', 'index': 0} 2024-08-05 19:12:48.155 DEBUG (MainThread) [custom_components.alexa_media.config_flow] Generating OTP from 387225 2024-08-05 19:13:14.744 DEBUG (MainThread) [custom_components.alexa_media.config_flow] Starting proxy for j***************l@g*******m - amazon.com File "/config/custom_components/alexa_media/config_flow.py", line 551, in async_step_totp_register File "/config/custom_components/alexa_media/config_flow.py", line 358, in async_step_start_proxy

debug log in homeassistant.log File "/config/custom_components/alexa_media/config_flow.py", line 551, in async_step_totp_register async def async_step_reauth(self, user_input=None): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/alexa_media/config_flow.py", line 358, in async_step_start_proxy self.proxy_view.handler = self.proxy.all_handler ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/yarl/_url.py", line 179, in __new__ raise TypeError("Constructor parameter should be str") TypeError: Constructor parameter should be str

joeuser000 commented 2 months ago

ok.. Update. I restarted a few times and tried again! Success....Not sure why but thank you for your assistant.

dj

joeuser000 commented 2 months ago

wait...i got a success message but go to integrations is says not loaded. will research.

danielbrunt57 commented 2 months ago

Are you still on HA Core: 2024.7.3?

joeuser000 commented 2 months ago

yes....AMP says "Not loaded" in the integrations panel. Nothing apparent in logs

Mally2004uk commented 2 months ago

@Mally2004uk Since you've not provided alexa_media & alexapy debug logs, I'm only guessing that you should start with whether your Amazon account works outside of this integration while using the email, password & TOTP/OTP secret that you've specified in the integration. The integration is now working with AMP 4.12.4 plus the files from the latest PR #2398...

I am all up and running now. Took me awhile to add the lines from PR #2398

chrisvblemos commented 2 months ago

Domains different from amazon.com are still not working for me. My best guess is there may be a problem related to the cookies being sent to the urls defined while attempting to get the csrf tokens (inside alexapy).

@danielbrunt57 May I suggest you clear all config entries, .storage, etc and try using a different domain inside AMP (like amazon.com.br or amazon.de) when first setting up AMP?

danielbrunt57 commented 2 months ago

It took me hours of chasing down the missing CONF_HASS_URL but in the end I believe I finally found it. I was sure I had already changed it but it must reverted during a recent PR revert that Alan had done.

image Lines 741-742:

        if CONF_HASS_URL in user_input:
            self.config[CONF_HASS_URL] = user_input[CONF_HASS_URL]
jleinenbach commented 2 months ago

It took me hours of chasing down the missing CONF_HASS_URL but in the end I believe I finally found it. I was sure I had already changed it but it must reverted during a recent PR revert that Alan had done.

Oh no. Right, it was reverted. But it was already fixed in my files when I tested it: amazon.de is still not working for me while amazon.com is working. IDK, but there were so many changes, maybe fix this with a new PR?

jleinenbach commented 2 months ago

Additional Minor Issues Noted During Configuration

jleinenbach commented 2 months ago

I deleted the configuration and the cookie, then it failed for amazon.de again:

2024-08-06 15:31:28.163 DEBUG (MainThread) [alexapy.alexalogin] 5 cookies successfully exchanged for refresh token for domain .amazon.de
2024-08-06 15:31:28.164 DEBUG (MainThread) [alexapy.alexalogin] Attempting to discover CSRF token
2024-08-06 15:31:28.315 DEBUG (MainThread) [alexapy.alexalogin] CSRF token not found from /spa/index.html
2024-08-06 15:31:28.595 DEBUG (MainThread) [alexapy.alexalogin] CSRF token not found from /api/devices-v2/device?cached=false
2024-08-06 15:31:28.660 DEBUG (MainThread) [alexapy.alexalogin] CSRF token not found from /templates/oobe/d-device-pick.handlebars
2024-08-06 15:31:28.725 DEBUG (MainThread) [alexapy.alexalogin] No csrf token found
2024-08-06 15:31:29.170 DEBUG (MainThread) [alexapy.alexalogin] GET: 
https://alexa.amazon.com/api/bootstrap returned 200:OK with response <CIMultiDictProxy('Content-Type': 'application/json', 'Content-Length': '181', 'Connection': 'keep-alive', 'Server': 'Server', 'Date': 'Tue, 06 Aug 2024 13:31:29 GMT', 'Vary': 'Content-Type,Accept-Encoding,User-Agent', 'x-amz-rid': '9MVHX5Y5SYD7JSDW7MQC', 'Set-Cookie': 'csrf=107031270; expires=Sun, 06-Aug-2034 13:31:28 GMT; Domain=.amazon.com; Path=/', 'x-amzn-RequestId': '9MVHX5Y5SYD7JSDW7MQC', 'x-amzn-alt-domain': 'https://alexa.amazon.de/logout', 'X-Cache': 'Miss from cloudfront', 'Via': '1.1 f36453eb82bc9ab0c6e360ac52cc5972.cloudfront.net (CloudFront)', 'X-Amz-Cf-Pop': 'FRA56-P8', 'X-Amz-Cf-Id': '5KRCnl5fA3NpYtsBuGUg5PO7TD4EweYH71CmqDU-fDndYZ_mGkz23Q==')>
2024-08-06 15:31:29.237 DEBUG (MainThread) [alexapy.alexalogin] GET: 
https://alexa.amazon.de/api/bootstrap returned 401:Unauthorized with response <CIMultiDictProxy('Content-Length': '0', 'Connection': 'keep-alive', 'Server': 'Server', 'Date': 'Tue, 06 Aug 2024 13:31:29 GMT', 'Strict-Transport-Security': 'max-age=0; includeSubDomains;', 'x-amz-rid': 'EHDMTSEBH2F6FMWEW35B', 'loginUrl': 'https://www.amazon.de/ap/signin?showRmrMe=1&openid.return_to=https%3A%2F%2Falexa.amazon.de%2Flogin&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.assoc_handle=amzn_dp_project_dee_de&openid.mode=checkid_setup&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&', 'x-amzn-RequestId': 'EHDMTSEBH2F6FMWEW35B', 'Vary': 'Content-Type,Accept-Encoding,User-Agent', 'X-Cache': 'Error from cloudfront', 'Via': '1.1 7432b1699c051c0940019ac02d9c3902.cloudfront.net (CloudFront)', 'X-Amz-Cf-Pop': 'MUC50-P6', 'X-Amz-Cf-Id': 'M3xxiaasP1M2OqBEEjcUU00puNaq5rw1xQ5DahaEKjVEgzTZHgBYZQ==')>
2024-08-06 15:31:29.238 DEBUG (MainThread) [alexapy.alexalogin] Not logged in: An exception of type ContentTypeError occurred. Arguments:
(RequestInfo(url=URL('https://alexa.amazon.de/api/bootstrap'), method='GET', headers=<CIMultiDictProxy('Host': 'alexa.amazon.de', 'User-Agent': 'AmazonWebView/Amazon Alexa/2.2.556530.0/iOS/16.6/iPhone', 'Accept': '*/*', 'Accept-Language': '*', 'DNT': '1', 'Upgrade-Insecure-Requests': '1', 'Accept-Encoding': 'gzip, deflate, br', 'Cookie': 'at-main=Atza|IwEBIDCZrNmIdg58JWwobvk0YDugVk4C5JiksmsDhCSOaJxOJNh06IoJlZesG4kZSCZt9hd72CtAEqruGWTsVwvgIc7Z3hRV7OgKyhN_7Z9ak4WDPOX1Y23Bu0gWYItDI4iU8PuCMeWyAqqvOSHjPBOrv3ykk-na6s-Py1BjMfk27CSqecyiAEJaW8al5rB2m1HYZVIpVMqqvvs1cByndEdhvhiVRXWmCGdgA1xAZkRUIQEI5S66NuVDt5PAD0EtdQ-2n4D_inlS4aBLFvSX6-VSFIr-GaJi_UexHFEqjkao19Zm4Q; lc-main=de_DE; sess-at-main="\\"0K6FmxT/8t/1pkEb9MMj8MWSirARx8Tbdq+myo/wRNo=\\""; session-id=261-7098128-0755204; session-id-time=2353671088l; session-token=akYPBowaBt6VqunJoXYrWTA1pCIggrBxPqDd6Nfd0oc0IN9moYzRuXntR8I4pbzz65x6DqsTpwX0VO7Pti+gaKDwo9P2w3hAzJ0wevHd94eX7RfZnvNasuANMy0XnCCA6YLB4GMMV9BBrcoFGzGyGWVHx3/bVmFXXPiCM3zQndeZ6l5dVL8+j5agHVnnGudI/vXFEiO6OvZJGxPyG4i4aDKoe7eKf74lQNaTp9GUMQXfcXcvkJK3XaUAK7T/GO9f9AZio+zoT/rEF6JjCLVBp4a3i0/9CFFLifjbbAqwYHuK8b8b89LRxoexnpPPKqp1byImLbHa/zN+U1UxIA2B7CRbIRdRHn2N; sid="\\"+NiqV2RFY5nyghOg8sF8HQ==|KnVxtuH/Gl1KbpMelx5J9LQXjH84Mp02CrJoyL6oX1s=\\""; ubid-acbde=134-1927251-7136836; ubid-main=134-1927251-7136836; x-main="\\"0fD?s68hNBmVcQsICi7oaSSl0T5f4Rjd\\""')>, real_url=URL('https://alexa.amazon.de/api/bootstrap')), ())

According to ChatGPT:

The error occurs because after deleting the configuration and cookies, the authentication for amazon.de fails. Here are some specific points and possible causes:

  1. CSRF Token Not Found:

    • Multiple attempts to discover the CSRF token fail (CSRF token not found). This indicates that the application is having trouble retrieving the necessary security token for authentication.
  2. Different Domains:

    • The response from https://alexa.amazon.com provides a CSRF token for the .amazon.com domain, but the subsequent request is made to https://alexa.amazon.de. This could cause an issue because cookies set for .amazon.com may not be applied to .amazon.de.
  3. Unauthorized Error:

    • The call to https://alexa.amazon.de/api/bootstrap returns a 401 Unauthorized response. This indicates that the authentication was not successful. The 401 response also includes a loginUrl, indicating that re-authentication is required.
  4. Set-Cookie Entries:

    • The response from https://alexa.amazon.com/api/bootstrap includes a Set-Cookie entry for csrf=107031270; expires=Sun, 06-Aug-2034; Domain=.amazon.com; Path=/, confirming that the CSRF token is set for .amazon.com and not .amazon.de.

Possible Solutions:

  1. Check Cookie Domains:

    • Ensure that cookies are correctly set for the appropriate domains. The CSRF token may need to be set for .amazon.de instead of .amazon.com.
  2. Synchronization of Authentication Domains:

    • Verify that the application correctly synchronizes between different Amazon domains (.com and .de). It may be necessary to configure the application specifically for one domain.
  3. Re-Login:

    • The Unauthorized error suggests that the session might be expired or invalid. Re-login via the provided loginUrl could resolve the issue.
  4. Debugging and Logging:

    • Enable detailed debugging and logging to better trace where the authentication process is failing.

By addressing these points, you can potentially identify and fix the issue, ensuring that authentication for amazon.de is successful.

joeuser000 commented 2 months ago

Upgraded to 2024.7.4 and loaded the "patched" AMP. Got through the OTP sign in however APM shows "Not Loaded" in Integrations. Error in logs.

`024-08-06 10:25:12.846 ERROR (MainThread) [homeassistant.setup] Error during setup of component alexa_media Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/setup.py", line 404, in _async_setup_component result = await task ^^^^^^^^^^ File "/config/custom_components/alexa_media/init.py", line 128, in async_setup for account in domainconfig[CONF_ACCOUNTS]:


KeyError: 'accounts'`
chrisvblemos commented 2 months ago

Relating to the problem of not being able to login on the AMP if domain is different from amazon.com even with the fixes provided by @danielbrunt57 in his PR #2398 .

I've successfully fixed the problem on my end and I can now login using non .com domains (amazon.com.br, amazon.co.uk, etc). It appears the problem comes from alexapy indeed. I've submitted an issue and a PR to alexapy's repo to see if any of what I'm saying makes sense or not. Let's see if it continues working tomorrow/etc.

Note: this is only for people who are using the AMP fixes mentioned above (the ones from PR #2398) and are still having trouble logging in - specially if your domain is not amazon.com. A temporary fix, if you do not wish to install a custom alexapy with the changes described in the issue I've submitted, you can try logging in with amazon.com domain instead. This might lead to other errors in the integration, as shown by the warning in the logs, so be warned :).

If you have issues while using the PR files or the workaround, it's better to wait for it to be pulled before submitting an issue to keep things organized (since we're technically not using the source code).

casa3c commented 2 months ago

It took me hours of chasing down the missing CONF_HASS_URL but in the end I believe I finally found it. I was sure I had already changed it but it must reverted during a recent PR revert that Alan had done.

image Lines 741-742:

        if CONF_HASS_URL in user_input:
            self.config[CONF_HASS_URL] = user_input[CONF_HASS_URL]

This issue is odd. I have restored a backup with the AMP version that you created a few weeks ago in your repository (Alexdanielbrunt57/alexa_media_player (integration) V. 4.10.3) And with that version I am able to carry out the OTP and AMP works in my home assistant perfecly.

image

moseisleydk commented 2 months ago

On newest HA core, and AMP 4.12.5 - stille have the Error 500 - Server got in trouble..

jleinenbach commented 2 months ago

On newest HA core, and AMP 4.12.5 - stille have the Error 500 - Server got in trouble..

This has nothing to do with the "Unknown error occurred" issue. You should open a new issue.

danielbrunt57 commented 2 months ago

On newest HA core, and AMP 4.12.5 - stille have the Error 500 - Server got in trouble..

And provide your debug logs!!

alexruffell commented 2 months ago

I've tried every 4.12.x version up to the latest .5 but cannot get it to work. I tried removing and readding with reboots in between. I am on the latest 2024.8 HA Core beta too, so I wonder whether my issues have something to do with that too as it appears some are able to get it working, but not all.

image

If I can be of any help with logs, etc. please let me know. Other than that, I'll sit in the sidelines and wait :) - Thanks for the hard work on this integration!

Edit: I am looking at a debug log and see errors related to CSRF tokens not found, and a lot more, however I also see stuff I do not feel comfortable sharing openly (NC HA URL, email used for Amazon login, cookie contents?, etc).

IsaTTeN commented 2 months ago

Hi I just updated HA to 2024.08 and 4.12.5 and now I got the warning. I deleted the integration and added again with amazon.com and amazon.es but I get the an error after OTP page: Alexa Media "Player can not Log in" This is the log: 2024-08-07 22:27:59.263 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry blahblah@gmail.com - amazon.es for alexa_media Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/config_entries.py", line 604, in async_setup result = await component.async_setup_entry(hass, self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/alexa_media/__init__.py", line 359, in async_setup_entry await login.login(cookies=await login.load_cookie()) File "/usr/local/lib/python3.12/site-packages/alexapy/helpers.py", line 137, in wrapper return await func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/alexapy/alexalogin.py", line 687, in login post_resp = await self._session.post( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/aiohttp/client.py", line 576, in _request raise err_exc_cls(url) aiohttp.client_exceptions.InvalidUrlClientError: /errors/validateCaptcha

joeuser000 commented 2 months ago

Upgrade HA to 2024.7.4 and installed "patched" AMP. de-installed, deleted pickle files in .storage, restarted HA. re-installed. AMP is now working.