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.51k stars 289 forks source link

aiohttp.client_exceptions.InvalidUrlClientError: /errors/validateCaptcha - solved by alexapy v1.28.2 but needs manual manifest.json edit #2418

Closed starkillerOG closed 2 months ago

starkillerOG 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

When updating to HA 2024.8.0 the alexa_media_player integration unfortunately broke for me. Was working fine on HA 2024.7.x. I think this has to do with a version bump of aiohttp.

Following error in the logs:
  File "/usr/local/lib/python3.12/site-packages/alexapy/alexalogin.py", line 687, in login
    post_resp = await self._session.post(

aiohttp.client_exceptions.InvalidUrlClientError: /errors/validateCaptcha

seems to me like the InvalidUrlClientError needs to be catched and a re-auth flow needs to be initialized.

To Reproduce

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior

Initialize a re-auth flow if needed.

Screenshots

System details

Logger: homeassistant.config_entries
Source: config_entries.py:604
First occurred: 10:16:34 PM (1 occurrences)
Last logged: 10:16:34 PM
Error setting up entry Amazon Alexa 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

Additional context

UlrichThiess commented 2 months ago

Even if you uninstall the Integration you can't install it.

Scope666 commented 2 months ago

Same problem here... I tried uninstalling and reinstalling, and I got this:

2024-08-07 16:43:45.751 WARNING (MainThread) [alexapy.helpers] alexaapi.get_guard_details((<alexapy.alexalogin.AlexaLogin object at 0x149ed2ddea20>,), {}): An error occurred accessing AlexaAPI: An exception of type AlexapyLoginError occurred. Arguments:
('Unauthorized',)
2024-08-07 16:43:45.751 WARNING (MainThread) [alexapy.helpers] alexaapi.get_network_details((<alexapy.alexalogin.AlexaLogin object at 0x149ed2ddea20>,), {}): An error occurred accessing AlexaAPI: An exception of type AlexapyLoginError occurred. Arguments:
('Unauthorized',)
2024-08-07 16:43:45.754 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved (None)
Traceback (most recent call last):
  File "/config/custom_components/alexa_media/__init__.py", line 251, in relogin
    if await test_login_status(hass, config_entry, login_obj):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/alexa_media/__init__.py", line 1421, in test_login_status
    ] = await hass.config_entries.flow.async_init(
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1293, in async_init
    flow, result = await self._async_init(flow_id, handler, context, data)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1323, in _async_init
    result = await self._async_handle_step(flow, flow.init_step, data)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 516, in _async_handle_step
    result: _FlowResultT = await getattr(flow, method)(user_input)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/alexa_media/config_flow.py", line 578, in async_step_reauth
    reauth_schema = self._update_schema_defaults()
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/alexa_media/config_flow.py", line 813, in _update_schema_defaults
    CONF_HASS_URL, default=self.config.get(CONF_HASS_URL, hass_url)
                                                          ^^^^^^^^
NameError: name 'hass_url' is not defined
2024-08-07 16:43:45.755 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved (None)
Traceback (most recent call last):
  File "/config/custom_components/alexa_media/__init__.py", line 251, in relogin
    if await test_login_status(hass, config_entry, login_obj):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/alexa_media/__init__.py", line 1421, in test_login_status
    ] = await hass.config_entries.flow.async_init(
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1293, in async_init
    flow, result = await self._async_init(flow_id, handler, context, data)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1323, in _async_init
    result = await self._async_handle_step(flow, flow.init_step, data)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 516, in _async_handle_step
    result: _FlowResultT = await getattr(flow, method)(user_input)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/alexa_media/config_flow.py", line 578, in async_step_reauth
    reauth_schema = self._update_schema_defaults()
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/alexa_media/config_flow.py", line 813, in _update_schema_defaults
    CONF_HASS_URL, default=self.config.get(CONF_HASS_URL, hass_url)
                                                          ^^^^^^^^
NameError: name 'hass_url' is not defined
2024-08-07 16:43:45.757 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved (None)
Traceback (most recent call last):
  File "/config/custom_components/alexa_media/__init__.py", line 251, in relogin
    if await test_login_status(hass, config_entry, login_obj):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/alexa_media/__init__.py", line 1421, in test_login_status
    ] = await hass.config_entries.flow.async_init(
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1293, in async_init
    flow, result = await self._async_init(flow_id, handler, context, data)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1323, in _async_init
    result = await self._async_handle_step(flow, flow.init_step, data)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 516, in _async_handle_step
    result: _FlowResultT = await getattr(flow, method)(user_input)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/alexa_media/config_flow.py", line 578, in async_step_reauth
    reauth_schema = self._update_schema_defaults()
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/alexa_media/config_flow.py", line 813, in _update_schema_defaults
    CONF_HASS_URL, default=self.config.get(CONF_HASS_URL, hass_url)
                                                          ^^^^^^^^
NameError: name 'hass_url' is not defined
2024-08-07 16:43:45.758 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved (None)
Traceback (most recent call last):
  File "/config/custom_components/alexa_media/__init__.py", line 251, in relogin
    if await test_login_status(hass, config_entry, login_obj):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/alexa_media/__init__.py", line 1421, in test_login_status
    ] = await hass.config_entries.flow.async_init(
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1293, in async_init
    flow, result = await self._async_init(flow_id, handler, context, data)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1323, in _async_init
    result = await self._async_handle_step(flow, flow.init_step, data)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 516, in _async_handle_step
    result: _FlowResultT = await getattr(flow, method)(user_input)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/alexa_media/config_flow.py", line 578, in async_step_reauth
    reauth_schema = self._update_schema_defaults()
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/alexa_media/config_flow.py", line 813, in _update_schema_defaults
    CONF_HASS_URL, default=self.config.get(CONF_HASS_URL, hass_url)
                                                          ^^^^^^^^
NameError: name 'hass_url' is not defined
2024-08-07 16:43:45.846 INFO (MainThread) [alexapy.alexaapi] Backing off _static_request(...) for 0.3s (aiohttp.client_exceptions.ClientConnectionError: Connector is closed.)
2024-08-07 16:43:45.927 INFO (MainThread) [alexapy.alexaapi] Backing off _static_request(...) for 0.2s (aiohttp.client_exceptions.ClientConnectionError: Connector is closed.)
2024-08-07 16:43:45.934 INFO (MainThread) [alexapy.alexaapi] Backing off _static_request(...) for 0.6s (aiohttp.client_exceptions.ClientConnectionError: Connector is closed.)
2024-08-07 16:43:46.153 WARNING (MainThread) [alexapy.helpers] alexaapi.get_authentication((<alexapy.alexalogin.AlexaLogin object at 0x149ed2ddea20>,), {}): An error occurred accessing AlexaAPI: An exception of type AlexapyLoginError occurred. Arguments:
('Login error detected; not contacting API',)
2024-08-07 16:43:46.178 WARNING (MainThread) [alexapy.helpers] alexaapi.get_devices((<alexapy.alexalogin.AlexaLogin object at 0x149ed2ddea20>,), {}): An error occurred accessing AlexaAPI: An exception of type AlexapyLoginError occurred. Arguments:
('Login error detected; not contacting API',)
2024-08-07 16:43:46.262 INFO (MainThread) [alexapy.alexaapi] Backing off _static_request(...) for 0.2s (aiohttp.client_exceptions.ClientConnectionError: Connector is closed.)
2024-08-07 16:43:46.268 INFO (MainThread) [alexapy.alexaapi] Backing off _static_request(...) for 1.0s (aiohttp.client_exceptions.ClientConnectionError: Connector is closed.)
2024-08-07 16:43:46.482 WARNING (MainThread) [alexapy.helpers] alexaapi.get_device_preferences((<alexapy.alexalogin.AlexaLogin object at 0x149ed2ddea20>,), {}): An error occurred accessing AlexaAPI: An exception of type AlexapyLoginError occurred. Arguments:
('Login error detected; not contacting API',)
2024-08-07 16:43:46.531 WARNING (MainThread) [alexapy.helpers] alexaapi.get_dnd_state((<alexapy.alexalogin.AlexaLogin object at 0x149ed2ddea20>,), {}): An error occurred accessing AlexaAPI: An exception of type AlexapyLoginError occurred. Arguments:
('Login error detected; not contacting API',)
2024-08-07 16:43:46.546 INFO (MainThread) [homeassistant.components.automation.kitchen_hats_auto_on] Kitchen Hats Auto ON: Running automation actions
2024-08-07 16:43:46.546 INFO (MainThread) [homeassistant.components.automation.kitchen_hats_auto_on] Kitchen Hats Auto ON: Executing step call service
2024-08-07 16:43:47.227 WARNING (MainThread) [alexapy.helpers] alexaapi.get_bluetooth((<alexapy.alexalogin.AlexaLogin object at 0x149ed2ddea20>,), {}): An error occurred accessing AlexaAPI: An exception of type AlexapyLoginError occurred. Arguments:
('Login error detected; not contacting API',)
stephenmhall commented 2 months ago

this isnt to do with the fact the Alexa web page we used to be able to access has gone and it points you to an app install? I have been unable to use the integration for a few updates now.

stephenmhall commented 2 months ago

and, if you click "install the app" it loads up an Amazon app store which tells you it is no longer supported on Windows 11 and all the apps will no longer be supported, and you dont seem to be able to install anything from it. Sorry if tis isn't relevant.

Scialla commented 2 months ago

same problem here, tried 2 time to remove and reinstall integration but can't install it

Jeepmb commented 2 months ago

Same issue here on upgrade to 2024.8

expozeur commented 2 months ago

Same issue.

Scope666 commented 2 months ago

Downgraded back to 2024.7.4 and it's working again, so something definitely broke this in 2024.8

MidnightLink commented 2 months ago

For anyone having this same issue, you can rollback your HA version by using Advanced SSH Terminal and inputting

ha core update --version=2024.7.4

Error log on 2024.8.1:

Logger: alexapy.helpers Source: custom_components/alexa_media/__init__.py:359 integration: Alexa Media Player ([documentation](https://github.com/alandtse/alexa_media_player/wiki), [issues](https://github.com/alandtse/alexa_media_player/issues)) First occurred: 5:30:17 PM (1 occurrences) Last logged: 5:30:17 PM alexalogin.login((<alexapy.alexalogin.AlexaLogin object at 0x7f67c5c18170>,), {'cookies': {}}): An error occurred accessing AlexaAPI: An exception of type InvalidUrlClientError occurred. Arguments: (URL('/errors/validateCaptcha'),)

L81ker commented 2 months ago

I have the same. I set debug on. Was working fine prior to 2024.8.

Note that I have cleaned my PIA data from this debug log, username is replaced with <<>> Alexa-Amazon-debug-log-redacted.txt

mazdarx2001 commented 2 months ago

For anyone having this same issue, you can rollback your HA version by using Advanced SSH Terminal and inputting

ha core update --version=2024.7.4

Thanks for this. I rolled mine back and can confirm its now working! Definitely keeping this version until I see a fix.

BobMac57 commented 2 months ago

For anyone having this same issue, you can rollback your HA version by using Advanced SSH Terminal and inputting ha core update --version=2024.7.4

Thanks for this. I rolled mine back and can confirm its now working! Definitely keeping this version until I see a fix.

Same here...

ob1w4nken0b1 commented 2 months ago

same here, unfortunately

guitosi commented 2 months ago

same here, 2024.08.0

jbrown9100 commented 2 months ago

Downgraded back to 2024.7.4 and it's working again, so something definitely broke this in 2024.8

It seems to me, that it may have to do with the unification of Services into Actions that something broke. 2024.7.4 put Services back.

guitosi commented 2 months ago

Downgraded back to 2024.7.4 and it's working again, so something definitely broke this in 2024.8

It seems to me, that it may have to do with the unification of Services into Actions that something broke. 2024.7.4 put Services back.

Thanks man, I downgraded and it worked again as you mentioned

bdraco commented 2 months ago

This looks like it could be a regression in aiohttp similar to the one I just fixed in https://github.com/aio-libs/aiohttp/pull/8632 but that PR likely doesn’t fix this issue

edit: It looks like a completely different problem

bdraco commented 2 months ago

https://github.com/aio-libs/aiohttp/pull/8158/files#diff-f334e752b4894ef951105572ab8b195aeb8db90eb6e48b1dfbd9a01da4c854f5R530

It looks like this PR added the exception where its raising but the comment in that PR implies it would fail anyways later

IainPHay commented 2 months ago

Downgraded back to 2024.7.4 and it's working again, so something definitely broke this in 2024.8

It seems to me, that it may have to do with the unification of Services into Actions that something broke. 2024.7.4 put Services back.

No it looks like it's an alexapy issue as mentioned in other threads see: https://github.com/alandtse/alexa_media_player/issues/2407#issuecomment-2272879665

chrisvblemos commented 2 months ago

aiohttp.client_exceptions.InvalidUrlClientError: /errors/validateCaptcha

Somehow alexapy is attempting to send a post request to the url "/error/validateCaptcha", clearly a malformed url, which is why the exception is being raised by aiohttp. Could be an uncaught issue on how alexapy finds that URL, could be that amazon updated some page, a combination of these, etc.

gtbdf1 commented 2 months ago

@alandtse I believe everyone who has upgraded to 2024.8 is having this issue.

chrisuk-web commented 2 months ago

Same issue here. Fixed by rolling back to 2024.7.4

Axsgranted commented 2 months ago

having the same issue. rolled back but now i can't re-add the integration. 2FA stuff not working...

doctorkb commented 2 months ago

I was having this issue, but managed to get it to work by deleting the integration entry, then adding a new one. When I added the new one, this was default: image

(that is not my local address -- I have https enabled and a proper URL). I tried a bunch of permutations using my proper local address, but it finally worked when I made it this: image

YMMV.

Axsgranted commented 2 months ago

I was having this issue, but managed to get it to work by deleting the integration entry, then adding a new one. When I added the new one, this was default: image

(that is not my local address -- I have https enabled and a proper URL). I tried a bunch of permutations using my proper local address, but it finally worked when I made it this: image

YMMV.

I deleted the integration. installed the previous version and did the 2FA setup. I use the string from the amazon site, verify the OTP and select the box and press submit. Each time I get "unknown error", and nothing in the logs.

Now Amazon thinks I've added 6 different devices.

doctorkb commented 2 months ago

Don't install previous version of this integration. Use the newest release.

The previous one was giving me that unknown error business too.

Axsgranted commented 2 months ago

Don't install previous version of this integration. Use the newest release.

The previous one was giving me that unknown error business too.

That was the ticket, thanks!

bfish2 commented 2 months ago

also having issue with 2024.8 - Following for updates

danielbrunt57 commented 2 months ago

Downgraded back to 2024.7.4 and it's working again, so something definitely broke this in 2024.8

It seems to me, that it may have to do with the unification of Services into Actions that something broke. 2024.7.4 put Services back.

Nope, nothing to do with services are now actions as that is just a code wrapper and it was working fine for me on the beta with actions from 8.0b0 up to and including 8.0b8. Then I got 8.0b9, installed it and 2024.8.0 was immediately presented which I installed and restarted and I now have this error:

aiohttp.client_exceptions.InvalidUrlClientError: /errors/validateCaptcha

In all likelihood, it comes down to aiohttp and alexapy and that is pretty much out of the scope of this integration. alexpy is rather old and only has a couple of people looking at it.

I will continue investigating but I make no promises of it working again...

myevit commented 2 months ago

Same here

kilrgt commented 2 months ago

I rolled back and it’s working fine, IM sure it will get looked at will be addressed in the next update. I did read all the comments and it’s interesting someone did get it to work tho.

danielbrunt57 commented 2 months ago

I may have spoken too soon! I reapplied the Cookies are not being forwarded to non .com domains patch to alexapy/alexaloin.py, did ha core restart and when I came back to my failed integrations page, I saw this...

image

So try the patch for alexapy v1.28.1...

lazyjai commented 2 months ago

+1 here.. having some issues with applying the patch.... alexalogin.py doesn't even exist on my system. can't even get python3 to run? no pip on the system so I can't get it to install alexapy....

Logs into amazon.com just fine, but doesn't log into amazon.ca where my echo devices are.

I'm very confused.

danielbrunt57 commented 2 months ago

+1 here.. having some issues with applying the patch.... alexalogin.py doesn't even exist on my system. can't even get python3 to run? no pip on the system so I can't get it to install alexapy....

Logs into amazon.com just fine, but doesn't log into amazon.ca where my echo devices are.

I'm very confused.

Have you gone to this root level of the container from your ssh session?

docker exec -it $(docker ps -f name=homeassistant -q) bash
Stephan-4711 commented 2 months ago

I applied the patch but I still get errors and AMP isn't loading:

`Logger: homeassistant.config_entries Quelle: config_entries.py:604 Erstmals aufgetreten: 06:51:28 (3 Vorkommnisse) Zuletzt protokolliert: 06:55:33

Error setting up entry email@domain.de - amazon.de 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 689, 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`

Tman-Tech commented 2 months ago

+1 Broken on 2024.8. Waiting for an update. I don't understand the patch thing?

baylf2000 commented 2 months ago

Also experiencing this issue. I've tried uninstalling and reinstalling multiple times. Not sure about how/where to apply the patch mentioned above.

danielbrunt57 commented 2 months ago

I applied the patch but I still get errors and AMP isn't loading:

Error setting up entry email@domain.de - amazon.de for alexa_media Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/alexapy/alexalogin.py", line 689, 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`

I had that error, applied the alexapy patch, restarted HA and all was fine...

danielbrunt57 commented 2 months ago

Also experiencing this issue. I've tried uninstalling and reinstalling multiple times. Not sure about how/where to apply the patch mentioned above.

The patch was originally mentioned here

ssh to HA

docker exec -it $(docker ps -f name=homeassistant -q) bash to get to the container level of HA

cd /usr/local/lib/python/3.12/site-packages/alexapy/

create the fix_cookies.patch file containing:

--- /tmp/alexalogin.py.orig
+++ /tmp/alexalogin.py.modified
@@ -1251,10 +1251,11 @@
                     # Strings are returned within quotations, strip them
                     else item["Value"][1:-1]
                 )
-                for name, value in item.items():
-                    if name in ["Name", "Value"]:
-                        continue
-                    raw_cookie[cookie_name][name] = f"{value}; Domain={domain}"
+                raw_cookie[cookie_name]["domain"] = domain
+                raw_cookie[cookie_name]["path"] = item["Path"]
+                raw_cookie[cookie_name]["secure"] = item["Secure"]
+                raw_cookie[cookie_name]["expires"] = item["Expires"]
+                raw_cookie[cookie_name]["httpOnly"] = item["HttpOnly"]                
                 # _LOGGER.debug("updating jar with cookie %s", raw_cookie)
                 self._session.cookie_jar.update_cookies(raw_cookie, URL(domain))
             _LOGGER.debug(

Then run:

apk --no-cache add patch
patch "/usr/local/lib/python3.12/site-packages/alexapy/alexalogin.py" < "fix_cookies.patch"
Stephan-4711 commented 2 months ago

After rebooting whole machine not just HA I get other errors an Notifitcation to reauthenticate against alexa. But how to re auth? `Logger: homeassistant.config_entries Quelle: config_entries.py:604 Erstmals aufgetreten: 07:17:18 (3 Vorkommnisse) Zuletzt protokolliert: 07:19:23

Error setting up entry my@domain.de - amazon.de 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 360, in async_setup_entry if await test_login_status(hass, config_entry, login): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/alexa_media/init.py", line 1421, in test_login_status ] = await hass.config_entries.flow.async_init( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1293, in async_init flow, result = await self._async_init(flow_id, handler, context, data) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1323, in _async_init result = await self._async_handle_step(flow, flow.init_step, data) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 516, in _async_handle_step result: _FlowResultT = await getattr(flow, method)(user_input) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/alexa_media/config_flow.py", line 578, in async_step_reauth reauth_schema = self._update_schema_defaults() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/alexa_media/config_flow.py", line 815, in _update_schema_defaults CONF_HASS_URL, default=self.config.get(CONF_HASS_URL, hass_url) ^^^^^^^^ NameError: name 'hass_url' is not defined`

lexiismadd commented 2 months ago

I'm having the same issue here using Home Assistant OS

danielbrunt57 commented 2 months ago

After rebooting whole machine not just HA I get other errors an Notifitcation to reauthenticate against alexa. But how to re auth?

Logger: homeassistant.config_entries Quelle: config_entries.py:604 Erstmals aufgetreten: 07:17:18 (3 Vorkommnisse) Zuletzt protokolliert: 07:19:23

Error setting up entry my@domain.de - amazon.de for alexa_media Traceback (most recent call last):

File "/config/custom_components/alexa_media/config_flow.py", line 578, in async_step_reauth reauth_schema = self._update_schema_defaults() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/config/custom_components/alexa_media/config_flow.py", line 815, in _update_schema_defaults CONF_HASS_URL, default=self.config.get(CONF_HASS_URL, hass_url) ^^^^^^^^ NameError: name 'hass_url' is not defined`

You need to apply PR #2417 just merged intp master and released as v4.12.6...

Tman-Tech commented 2 months ago

Just redownloaded and running v4.12.6... I re-configured and am having the same error.

danielbrunt57 commented 2 months ago

Just redownloaded and running v4.12.6... I re-configured and am having the same error.

The patch was originally mentioned https://github.com/alandtse/alexa_media_player/issues/2407#issuecomment-2272879665

ssh to HA

docker exec -it $(docker ps -f name=homeassistant -q) bash to get to the container level of HA

cd /usr/local/lib/python/3.12/site-packages/alexapy/

create the fix_cookies.patch file containing:

--- /tmp/alexalogin.py.orig
+++ /tmp/alexalogin.py.modified
@@ -1251,10 +1251,11 @@
                     # Strings are returned within quotations, strip them
                     else item["Value"][1:-1]
                 )
-                for name, value in item.items():
-                    if name in ["Name", "Value"]:
-                        continue
-                    raw_cookie[cookie_name][name] = f"{value}; Domain={domain}"
+                raw_cookie[cookie_name]["domain"] = domain
+                raw_cookie[cookie_name]["path"] = item["Path"]
+                raw_cookie[cookie_name]["secure"] = item["Secure"]
+                raw_cookie[cookie_name]["expires"] = item["Expires"]
+                raw_cookie[cookie_name]["httpOnly"] = item["HttpOnly"]                
                 # _LOGGER.debug("updating jar with cookie %s", raw_cookie)
                 self._session.cookie_jar.update_cookies(raw_cookie, URL(domain))
             _LOGGER.debug(

Then run:

apk --no-cache add patch
patch "/usr/local/lib/python3.12/site-packages/alexapy/alexalogin.py" < "fix_cookies.patch"
Tman-Tech commented 2 months ago

Just redownloaded and running v4.12.6... I re-configured and am having the same error.

The patch was originally mentioned #2407 (comment)

ssh to HA

docker exec -it $(docker ps -f name=homeassistant -q) bash to get to the container level of HA

cd /usr/local/lib/python/3.12/site-packages/alexapy/

create the fix_cookies.patch file containing:

--- /tmp/alexalogin.py.orig
+++ /tmp/alexalogin.py.modified
@@ -1251,10 +1251,11 @@
                     # Strings are returned within quotations, strip them
                     else item["Value"][1:-1]
                 )
-                for name, value in item.items():
-                    if name in ["Name", "Value"]:
-                        continue
-                    raw_cookie[cookie_name][name] = f"{value}; Domain={domain}"
+                raw_cookie[cookie_name]["domain"] = domain
+                raw_cookie[cookie_name]["path"] = item["Path"]
+                raw_cookie[cookie_name]["secure"] = item["Secure"]
+                raw_cookie[cookie_name]["expires"] = item["Expires"]
+                raw_cookie[cookie_name]["httpOnly"] = item["HttpOnly"]                
                 # _LOGGER.debug("updating jar with cookie %s", raw_cookie)
                 self._session.cookie_jar.update_cookies(raw_cookie, URL(domain))
             _LOGGER.debug(

Then run:

apk --no-cache add patch
patch "/usr/local/lib/python3.12/site-packages/alexapy/alexalogin.py" < "fix_cookies.patch"

How do I do this?? Sorry, I'm pretty new to home assistant.

EzeCuervo commented 2 months ago

Also experiencing this issue. I've tried uninstalling and reinstalling multiple times. Not sure about how/where to apply the patch mentioned above.

The patch was originally mentioned here

ssh to HA

docker exec -it $(docker ps -f name=homeassistant -q) bash to get to the container level of HA

cd /usr/local/lib/python3.12/site-packages/alexapy/

create the fix_cookies.patch file containing:

--- /tmp/alexalogin.py.orig
+++ /tmp/alexalogin.py.modified
@@ -1251,10 +1251,11 @@
                     # Strings are returned within quotations, strip them
                     else item["Value"][1:-1]
                 )
-                for name, value in item.items():
-                    if name in ["Name", "Value"]:
-                        continue
-                    raw_cookie[cookie_name][name] = f"{value}; Domain={domain}"
+                raw_cookie[cookie_name]["domain"] = domain
+                raw_cookie[cookie_name]["path"] = item["Path"]
+                raw_cookie[cookie_name]["secure"] = item["Secure"]
+                raw_cookie[cookie_name]["expires"] = item["Expires"]
+                raw_cookie[cookie_name]["httpOnly"] = item["HttpOnly"]                
                 # _LOGGER.debug("updating jar with cookie %s", raw_cookie)
                 self._session.cookie_jar.update_cookies(raw_cookie, URL(domain))
             _LOGGER.debug(

Then run:

apk --no-cache add patch
patch "/usr/local/lib/python3.12/site-packages/alexapy/alexalogin.py" < "fix_cookies.patch"

Thanks! This works great. After restart HA, my devices came back to life.

Tman-Tech commented 2 months ago

Thanks! This works great. After restart HA, my devices came back to life.

How exactly did you do this? I'm new to home assistant.

danielbrunt57 commented 2 months ago

How do I do this?? Sorry, I'm pretty new to home assistant.

No worries, we all were there at one point! Do you have the Terminal add-on installed?

Tman-Tech commented 2 months ago

No worries, we all were there at one point! Do you have the Terminal add-on installed?

Yes, Advanced SSH and web terminal.

danielbrunt57 commented 2 months ago

Ok, in there, start with the docker exec -it $(docker ps -f name=homeassistant -q) bash command