Error while setting up platform alexa_media - KeyError: 'csrf'
See original GitHub issueDescribe the bug TTS was not working anymore. I suspected an old cookie etc, deleted the .pickle file and restarted homeassistant which always worked. Configuration with 2FA seemed to work. Afterwards I started to see the following errors in the log:
Error while setting up platform alexa_media
Traceback (most recent call last):
File "/usr/src/app/homeassistant/helpers/entity_platform.py", line 126, in _async_setup_platform
SLOW_SETUP_MAX_WAIT)
File "/usr/local/lib/python3.7/asyncio/tasks.py", line 416, in wait_for
return fut.result()
File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/alexa_media/alarm_control_panel.py", line 35, in setup_platform
hass) \
File "/config/custom_components/alexa_media/alarm_control_panel.py", line 73, in __init__
self.alexa_api = AlexaAPI(self, login)
File "/usr/local/lib/python3.7/site-packages/alexapy/alexaapi.py", line 51, in __init__
csrf = self._session.cookies.get_dict()['csrf']
KeyError: 'csrf'
To Reproduce Steps to reproduce the behavior:
- Delete .pickle
- Restart HA
- Configure (Login)
- Error appear
Expected behavior Media Players should appear along the functionality
Screenshots If applicable, add screenshots to help explain your problem.
System details
- Home-assistant (version): 0.95.4 (docker)
- Hassio (Yes/No): No
- alexa_media (version from
const.py
or HA startup): v1.3.1 - alexapy (version from
pip show alexapy
or HA startup): 0.7.0
Additional context Add any other context about the problem here.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:7
- Comments:57
Top Results From Across the Web
Echo Devices (Alexa) as Media Player - Testers Needed
I found out (the long way) that alexa media doesn't work with HA 96.2 (on a ... Error while setting up platform alexa_media...
Read more >How do you solve the error KeyError: 'A secret key is required ...
The easiest way to solve this would be to set up a secret key in your ... WRF CSRF SECRET_KEY otherwise your secret...
Read more >KeyError CSRF: /home/Support/LabKey Support Forum
This was the response when we passed 'disable_csrf=True', while passing 'disable_csrf=False' we are getting the error "Key Error = CSRF".
Read more >custom_components - Bountysource
If i use the Aleaxa app to do the annoncement it works perfect. In the FAQ is mentioned to check that "Communications" is...
Read more >Alexa in Home Assistant - TTS, Sound Effects ... - YouTube
In todays video we are setting up the Alexa Media Player in Home Assistant. This will allow us to make use of TTS...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
First a huge thx @jfautley now works again!
@erichter2018 the simplest way would be to go to the “Configurator” then clic on settings and on “Execute shell Command” Paste here the command given by Jon:
pip3 install --target /config --no-dependencies git+https://gitlab.com/jfautley/alexapy
Then don’t forget to delete your .pickle file in your /config directory and reboot 😉
It looks like Amazon have tweaked the API, and the AlexaPy library no longer gets the CSRF token from the login URL (and there’s no error checking in the init function there).
Given the upstream maintainers lack of time, I’ve forked the AlexaPy repo and updated the site - I’d raise a PR but it’s a one line change and I’ve not done anything to actually test it - but it works for me.
You can find the updated repo at https://gitlab.com/jfautley/alexapy - I’ve tested this against an Amazon UK account using Hass.IO.
To install (on Hass.IO), SSH into your instance and run:
pip3 install --target /config --no-dependencies git+https://gitlab.com/jfautley/alexapy
For other Home-Assistant installs, you should be able to use
--target /path/to/config/deps
but for some reason the PYTHONPATH on Hass.IO is messed up… 🤷♂