alexa_media_player: Alexa Media Player fails to initialize after restarting HA 2024.6.3 due to partitioned cookie
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
Alexa Media Player is failing to initialize after restarting HA 2024.6.3. If I reload the integration, all is well.
To Reproduce
Restart Home assistant 2014.6.3 and observe that the integration failed to load.
Expected behavior
It should load like it did on 2024.6.2 and older.
Screenshots
System details
- Home-assistant (version): 2024.6.3
- alexa_media (version from
const.pyor HA startup): 4.10.2 - alexapy (version from
pip show alexapyor HA startup):
- alexa_media # pip show alexapy
WARNING: Package(s) not found: alexapy
- Amazon 2FA is enabled (y/n) : Yes
Logs
home-assistant_2024-06-17T13-08-27.618Z.log
Additional context
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 22
- Comments: 193 (12 by maintainers)
Commits related to this issue
- fix: bump alexapy to 1.29.2 closes #2288 — committed to alandtse/alexa_media_player by alandtse 2 years ago
I also have this issue. The integration fails to start every time I restart HA. And it succeed to load by reloading the integration. The error is always
The issue started about 1-2 weeks ago. I never experienced this before.
Thanks, I’ve submitted my PR. @alandtse Please see https://gitlab.com/keatontaylor/alexapy/-/merge_requests/376
I’m gonna go have a beer (or two) to celebrate…
I have the same issue, I need to manually reload integration after each restart, reload seems to work each time.
***NEW DEVELOPMENT ***
The cutoff for new features in Python 3.13 was at the beginning of the beta cycle on 2024-05-08. Python new features won’t happen again now until 3.14 but the partitioned cookie PR might get looked at as “type-security/bug fix”.
Ref: gh-112713 : Add support for ‘partitioned’ attribute in http.cookies #112714
In the midst of the above, I went hunting again and found a PR from 3 weeks ago for the Unifi add-on which which also has/had partitioned cookie trouble. That PR was Bump aiounifi to v80 #124004.
aiounifiis a library much likealexapy. I went looking through theaiounifilibrary and found code inconnectivity.pythat resolves the partitioned cookie issue:I added that code to alexapy/alexalogin.py and it eliminated the partitioned cookie error in
python3.12/http/cookies.py. I’ve submittedalexapymerge request: #386Changed back to original cookies.py and restart HA: Problem exists. Changed alexalogin.py and restart HA: no Problems Second restart: no Problems Thrid restart: no Problems
My workaround for now is this automation:
alexapy version 1.29.2 is released and has resolved the partitioned cookie error! Edit your manifest.json to:
Here goes…
https://github.com/amitfin/patch,Category: Integrationpatchand added that shared folder to Setting > System > Storage > Network storage aspatches. That creates a folder in Home Assistant/share/namedpatches. Alternatively, you can just create the/share/patchesfolder which will then reside on your HA storage device.configuration.yamlfile:Ok the tone is getting out of hand. Please remember there are human beings at the other end of the pipes.
As @danielbrunt57 is volunteering to respond to issues and provide code, I’ve been deferring to him on the close decision frankly because I’m not following the issues closely. I was actually about to provide him contributor privileges to do it without asking me.
That said, we can leave this open. But please keep things civil. I don’t have time or the interest to come moderate disputes.
If you’re concerned about the integration dying, consider helping out with code, translations, or responding to issues. Otherwise I could see @danielbrunt57 deciding to just avoid the trouble completely.
Hacking the code inside the HA docker needed to be repeated every time you upgrade HA. Having an automation to reload after 1 minute. Works. Is horrible. Waiting until October where HA Maybe upgrades Python and that will maybe fix it (we cannot be sure)
Why can’t this component be modified so it delays its loading so it works for everyone. All users that do not see this bug report will have no clue. And when you close it - it becomes practically invisible. Users will have an issue, come here to look for open bugs. Find none. Is this component only for geeks?
I do not personally trust that this custom component will exist much longer.
I’ve found a solution which is working for me. My issue seems to be in alexapy which is using python 3.12. It’s cookies.py does not define partitioned in the cookie dictionary, which for some reason is what my setup is encountering during first initialization after restart but not during a reload. I found this PR: gh-112713 : Add support for ‘partitioned’ attribute in http.cookies #112714 which has been approved for python 3.13 but hasn’t been finalized yet and still has to go through several betas before official ETA release in October. This would seem to be needed now as MS Edge (my default browser) seems to already be creating partitioned cookies (CHIPS) and I’ve read that Google Chrome recently started rolling it out as well.
First, edit
config/custom_components/alexa_media/manifest.jsonand add “websocket_api” to “dependencies”:Then, in the homeassistant container, I replaced
/usr/local/lib/python3.12/http/cookies.pywith the newer python3.13 cookies.py file from https://github.com/giles-v/cpython/blob/add-cookies-partitioned-support/Lib/http/cookies.py (Line 285 is where “partitioned” has been added to the cookie dictionary):My Alexa Media Player integration is now initializing first time, every time!
Yeah please re-open this issue. It’s not a 1 time occurrence anymore and is every restart.
But now it’s happening on every restart ever since the upgrade. That FAQ entry only mentions “on upgrade”. Implying the first time. Not every time.
I’ve managed to submit a clean MR to
alexapyto finally fix/address this issue.The code change is in the first 60 lines (up to
class AlexaLogin:)/usr/local/lib/python3.12/site-packages/alexapy/alexalogin.pyBasically, change:
from http.cookies import SimpleCookietofrom http.cookies import Morsel, SimpleCookieand add this new code:It all started with the partitioned cookie issue which led me delve deeply insure AMP and alexapy and has been a steep ongoing learning curve for me. Then I tacked a feature request to be able to reconfigure all options where I had a lot more learning to do and I made mistakes, etc. Then HA 2024.8.0b0 arrived and apparently revamped aiohttp which introduced more problems which are still trying to be figured out. Someone else is working on a new AMP integration but it’s still months away and might not have much more if anything than just Media Payer functionality. So it’s all been a complicated mix of things all occuring more or less at the same time. In the beginning, AMP lacked a lot of what it’s grown into over the years and when that sort of morphing occurs, code can become complex and confusing. Plus Amazon constantly evolving and changing tends to make matters even worse…
You seem miss my points. You need to mobilize some enphathy and try to put yourself in the minds of users that are not Python programmers.
It is an unacceptable hack having to penetrate the HA docker container, patch code and then see it all reverted each time you install a HA patch release which will happen probably 10-12 times before it includes a new Python version. No user can be satisfied with that as an acceptable work around.
The automation work around is acceptable. But you need to know it. You need to be able to find it. And very few will find it if it is hidden as a closed bug. People should not expect having to find information about workarounds about a bug that is still present showing its ugly face for most, probably all users. Why is it important to close the bug? Do you pay money to Github for every open bug? What good does it do to anyone?
I have personally installed 5 Raspberry Pi Zero 2W with Jabra speakers and use these for my house TTS announcements. I expect this integration will die within a few months. Sad. It has worked well for years.
This is a WooHoo! moment for me…
I gave up on the partitioned cookie issue and re-replaced cookies.py with the new 3.13 PR version, which I will have to do every week until HA upgrades to it, and returned to coding the enhanced options input.
The hack of files inside the HA container is a bit risky business. Hacking a custom component I dare. Adding the websocket dependency does not fix it. I am not strong enough in understand docker to attempt hacking code inside HA
I do not understand several things.
What does your experiences with your browser have to do with Home Assistant running in a Linux on a server? Why would the browser used to restart HA make the Python code run differently? I restart my HA from Safari browser on an iPad normally.
And why does the same Python code on the server fail when HA starts up, but works just fine when the integration is reloaded. They key to finding the root cause must and a fix. What is it in HA that is not ready when the integration attempts to start?
AMP 4.13.1 now requires
alexapy==1.29.2which fixes the errorhttp.cookies.CookieError: Invalid attribute 'partitioned'Thecookies.pypatch is no longer required. If you are having other issues after updating, please do not post them here! Thanks!Hello everyone, I decided to update HA from 2024.7.4 (where AMP was still working) to HA 2024.9.1. I removed AMP and its integration. After reinstalling the custom integration of AMP from HACS I can no longer install AMP. During the procedure it takes me back to the login site but nothing happens, just a continuous loop of email and password requests without being able to connect. I ask you to help me because I don’t know what to do anymore.
I also tried to follow some suggestions from @danielbrunt57 but to no avail. I modified the manifest file but nothing. I don’t know what to do anymore and I find it very difficult to follow this topic because I’m not very practical with programming.

I think I’m going to avoid updating anything for a while. Home automation is great until it stops automating. And then your entire family suffers.
again, thanks for your heroic efforts. there hasn’t even been a peep from the actual authors of AMP…
@danielbrunt57 - Works like a champ. VERY MUCH appreciated. Once again, I went to battle with this integration for several hours today and this “fix” worked right outta the gate.
I’m getting REALLY tired of the constant and ongoing problems with this integration. Alexa has to be in at least half of the HA instillations (the other half Googles Assistant). Why isn’t such an important integration handled by the core team?
PS: you might mention that after adding the custom repository, you need to download the patch integration.
As I think I stated before, Python 3.13 is not scheduled to be out of beta until October and it may be a month or more before HA updates to 3.13. The PR for partitioned cookie support appears to still be on track as a
Featurefor3.13, but we might see a new AMP integration before all that happens as this one is now on life support.Yes, I made that fix and that change wasn’t going to fix this issue. It was to fix a different issue.
Alan is still publishing fixes provided by other developers. So this integration is in maintenance mode. Myself and a few others have been pushing various minor fixes to the integration. He is not actively developing this integration or providing fixes authored by him.
I just installed HA 2024.6.4 and rebooted, but the problem seems to persist.
Try inside the .storage folder.
On Fri, 21 Jun 2024, 15:09 carvan, @.***> wrote:
Good evening, I installed a clean version of Home Assistant on another PC (intel nuc) and started the installation procedure of Alexa media player but I encountered the same problem that is the procedure brings me back to the login site but nothing happens, just a continuous cycle of email and password requests without being able to connect. Do you have any solution?
So am I interpreting this correctly, if an RP is submitted now, we get the fix via the official release and no longer have to use workarounds here?
If this is the case, I would like to save myself the manual work. What happens if I install it like this? Is it then consistent? Or will it be overwritten with the next (fixed) update?
Sorry if I’m perhaps asking stupid questions, but I haven’t yet delved that deeply into the architecture of HA, as I’m actually only a user and not a developer 😉
@danielbrunt57 are you planning to bump alexapy too with your other PRs? That should close this issue. I’m holding off on the next release since I thought that was forecoming.
custom_components/alexa_media folder
cookies.py is an easy fix in docker, copy the updated cookies.py locally and mount the updated file readonly into the container:
I’ve edited my post above, thanks!
You’re right, I overlooked that minor but important detail.
Partitioned cookies are rather new in the browser/website realm (google CHIPS). The cookies.py I found is from a pull request for Python 3.13 beta to support partitioned cookies. There was lots of back and forth on the subject in the python community since Dec/Jan but it’s looking like the PR will likely be merged. We won’t see it in HA until 3.13 final comes out and even then HA core will have to do their tests with it before switching HA to Python 3.13. They might already be doing that with the 3.13 beta but I’m only guessing…
I was using the automation from the beginning to fix the problem but today I have noticed that it fixes the issue no more.
use
Advanced SSH & Web Terminalwith enabledSafe ModethenI was already using the original cookies.py file so I just made the changes to alexalogin.py. Then restarted it 3 times and it started each time on its own. Thanks @danielbrunt57 !
Ill try. Wait…
That solution has already been posted! Also, please format your posts correctly by surrounding your code with triple back quotes before and after the code on their own line. Or select the code segment and use the editor’s <> button to encase the block with triple backquotes.
AMP doesn’t even initialize me. I already put the error above
After getting 2024.7.0 on Wednesday and also upgrading to the latest AMP, no the issue persists. I just now decided to retry core-2024.7.0 with a different test:
Note: I added
"hacs"dependency to manifest.json otherwise AMP would be in the 1st initializing state for a v e r y long time.Using the original python3.12 cookies.py file without partitioned cookie support, this worked for me but it does delay my complete startup by a lot. I will probably go back to the python3.13 file…
@danielbrunt57 Sorry I didn’t check for partitioned cookie error before I rolled back. I just tried again and restarted 6 times but have not gotten the error yet. Alexa Media player is still loading as it should. If I do get it later, I will check for error.
@danielbrunt57 thank you for your suggestion. I confirm that following the above (https://github.com/alandtse/alexa_media_player/issues/2288#issuecomment-2181877003 )recommendation fixed my problem
I deleted the Alexa Media Player integration in HA 2024.6.4, deleted the custom component in HACS and restarted HA. I then deleted the following files in /config/.storage: -rw-r–r-- 1 root root 98 Jun 9 00:39 alexa -rw-r–r-- 1 root root 783 Jun 26 16:13 alexa_auth -rw-r–r-- 1 root root 2577 Jun 26 16:44 alexa_media.daniel@brunt.ca.pickle
I re-installed Alexa Media Player Custom Component in HACS, restarted HA and re-installed the Alexa Media Player integration and, after three HA restarts, Alexa Media Player is initializing just fine now.
It might be worth noting that before starting the above exercise, I reviewed my settings in Edge browser and in
Privacy, search and serviceswhere I had changedBalancedtoBasicsome number of weeks ago, I changed it back toBalanced.So for me, this is no longer an issue.
For me, renaming the .pickle file and deleting the integration worked as this forced a re-authentication when adding the integration back in. Have not restarted since doing that so unsure if it’s persistent.
Mine does’t work even after reloading it. HA 2024.6.3