alexa_media_player: "Alexa Media Player failed to login" when adding integration for amazon.co.uk: `Not logged in: An exception of type ContentTypeError occurred`
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 adding the AMP integration using the amazon.co.uk region, login to amazon is successful but then the integration states:
To Reproduce
- Remove the AMP integration
- Re-add the AMP integration setting the amazon region to
amazon.co.uk - Login to amazon through the proxy page
- Once the proxy page closes, the error is displayed
Expected behavior
Should be able to add the integration for the amazon.co.uk region.
Screenshots
System details
- Home-assistant (version): 2024.8.1
- alexa_media (version from
const.pyor HA startup): 4.12.7 - alexapy (version from
pip show alexapyor HA startup): Not sure how to find this in HAOS. Doesn’t seem to be in the logs? - Amazon 2FA is enabled (y/n). <!—We will not debug login issues if unanswered—>: y
Logs Please provide logs.
Apologies if this is excessively redacted.
2024-08-18 16:17:20.261 DEBUG (MainThread) [alexapy.alexalogin] 5 cookies successfully exchanged for refresh token for domain .amazon.co.uk
2024-08-18 16:17:20.263 DEBUG (MainThread) [alexapy.alexalogin] Attempting to discover CSRF token
2024-08-18 16:17:20.383 DEBUG (MainThread) [alexapy.alexalogin] CSRF token not found from /spa/index.html
2024-08-18 16:17:20.626 DEBUG (MainThread) [alexapy.alexalogin] CSRF token not found from /api/devices-v2/device?cached=false
2024-08-18 16:17:20.684 DEBUG (MainThread) [alexapy.alexalogin] CSRF token not found from /templates/oobe/d-device-pick.handlebars
2024-08-18 16:17:20.728 DEBUG (MainThread) [alexapy.alexalogin] No csrf token found
2024-08-18 16:17:21.124 DEBUG (MainThread) [alexapy.alexalogin] GET:
https://alexa.amazon.com/api/bootstrap returned 200:OK with response <CIMultiDictProxy('Content-Type': 'application/json', 'Content-Length': '172', 'Connection': 'keep-alive', 'Server': 'Server', 'Date': 'Sun, 18 Aug 2024 15:17:21 GMT', 'Vary': 'Content-Type,Accept-Encoding,User-Agent', 'x-amz-rid': '29EZT64H7XHEE5M0K0ER', 'Set-Cookie': 'csrf=-701784766; expires=Fri, 18-Aug-2034 15:17:20 GMT; Domain=.amazon.com; Path=/', 'x-amzn-RequestId': '29EZT64H7XHEE5M0K0ER', 'x-amzn-alt-domain': 'https://alexa.amazon.co.uk/logout', 'X-Cache': 'Miss from cloudfront', 'Via': '1.1 ce6dd6cf8e3b2bf695c066e441ad568e.cloudfront.net (CloudFront)', 'X-Amz-Cf-Pop': 'LHR61-P6', 'X-Amz-Cf-Id': 'l0vWnUXdmXysduXb9GVKjiCRjCUb0_4RDTxQiw8OZTSXDrilcU50bA==')>
2024-08-18 16:17:21.167 DEBUG (MainThread) [alexapy.alexalogin] GET:
https://alexa.amazon.co.uk/api/bootstrap returned 401:Unauthorized with response <CIMultiDictProxy('Content-Length': '0', 'Connection': 'keep-alive', 'Server': 'Server', 'Date': 'Sun, 18 Aug 2024 15:17:21 GMT', 'Strict-Transport-Security': 'max-age=0; includeSubDomains;', 'x-amz-rid': 'GS2055T72KC6WFXSRBD8', 'loginUrl': 'https://www.amazon.co.uk/ap/signin?showRmrMe=1&openid.return_to=https%3A%2F%2Falexa.amazon.co.uk%2Flogin&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.assoc_handle=amzn_dp_project_dee_uk&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': 'GS2055T72KC6WFXSRBD8', 'Vary': 'Content-Type,Accept-Encoding,User-Agent', 'X-Cache': 'Error from cloudfront', 'Via': '1.1 6cd1874959ee48e26855209aa18a4014.cloudfront.net (CloudFront)', 'X-Amz-Cf-Pop': 'LHR50-P7', 'X-Amz-Cf-Id': 'a_kCzoW7gXbKbd_13B1UiHWlFsEnNgovCnc9TFi6p1N7mxi0Kq7pjw==')>
2024-08-18 16:17:21.168 DEBUG (MainThread) [alexapy.alexalogin] Not logged in: An exception of type ContentTypeError occurred. Arguments:
(RequestInfo(url=URL('https://alexa.amazon.co.uk/api/bootstrap'), method='GET', headers=<CIMultiDictProxy('Host': 'alexa.amazon.co.uk', '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=<REDATED>; lc-main=en_GB; sess-at-main="\\"<REDACTED>\\""; session-id=258-2185812-7023702; session-id-time=2354714240l; session-token=<REDACTED>; ubid-acbuk=130-0156096-0538242; ubid-main=130-0156096-0538242; x-main=<REDACTED>')>, real_url=URL('https://alexa.amazon.co.uk/api/bootstrap')), ())
Additional context
I have found a partial workaround to add the amazon.co.uk config entry, but it does not result in a functioning AMP integration. Instead, the integration prompts to be reconfigured (possibly one of the other issues such as #2453), and has some strange behaviour possibly as a result of the same account being registered in two config entries (conflicting pickle file?)
The workaround to add the config entry:
- Add the AMP integration but using the
amazon.comregion. - Once logged in to amazon, the AMP integration will be added, but will fail to start.
- Click the 3 dot menu for the failing entry and select “System options”
- Turn off both options and save:
- Click “Add entry” and complete the setup this time for
amazon.co.ukregion - The integration should add successfully, but will then prompt to be re-configured:
Remove theamazon.comentry.
Edit: Removing the entry seemingly removes both the amazon.com and amazon.co.uk entries. Possibly a conflicting ID (email?) causing some strange behaviour.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 34 (6 by maintainers)
I decided that there was nothing more important in the latest HA update that I needed more than using Alexa Media Player so, as I always keep backups, I went back to *Core 2024.7.4 *and am waiting for all the mess to be sorted out! I am also steering clear of Alexa Media Player updates and am staying with version 4.12.5 for the time being!
It’s taking some time to get this sorted out.
On Mon, 2 Sept 2024 at 13:50, andrea-git @.***> wrote:
I’m pretty sure it’s affecting thousands!
On Sun, 1 Sept 2024 at 11:09, David Miller @.***> wrote:
Could you try this:
docker exec -it homeassistant bashcd /usr/local/lib/python3.12/httpcookies.pywith cookies.zipcd ../site-packages/alexapyalexalogin.pywith alexalogin.zipasync def delete_cookiefile(self)which AMP 4.12.8 will call to delete the pickle file when removing the config entry.Seconds between scans360- with http2push active, this effectively becomes 1 hour (3600 seconds)Include devices connected via EchoSystem optionsEnable newly added entitiesbut leaveEnable polling for updatesenabledNeed to see debug log trace for
alexapy,authcaptureproxyandalexa_media…My Alexa Media player has been failing to log in too. I’ve just tried deleting and re-adding the integration, and even clearing all my 2FA settings, but I still get the ‘Alexa Media Player failed to log in’ error. I updated to HA 2024.8.3 (I was previously on 8.1) and tried again, but I still can’t make it work.
Finding this open issue, hopefully this is a general issue with the integration which will be fixed in a future update? Or is this only affecting isolated accounts?
I have the same (?) problems with amazon.de. At least the error messages are looking similar.
tried this already as well.
HA 2024.8.2 AMP v4.12.10
@jleinenbach
pip show aiohttpis showing as v3.10.3 for me. I believe it was updated in HA 2024.8.2 which I have updated to but the issue is still present for me.Are you using
amazon.defor the region? Based on thex-acbukcookie name, this may be anamazon.co.ukspecific issue.amazon.comdoesn’t seem to have the same problem.I made some adjustments to the logging in
alexalogin.pyusing the steps mentioned by @danielbrunt57 to try get some more diagnostics (adjusting some existing messages and adding output offilter_cookies("f{self._prefix}{self.url}")in various places) but I’m not seeing them take effect. I deleted the__pycache__to be sure but it isn’t being regenerated.pip show alexapyseems to indicate it is the correct location so I’m not sure what is happening.I don’t have any other version of
alexalogin.pyin thealexapydirectory. The steps I’m using:docker exec -it homeassistant bashcd /usr/local/lib/python3.12/site-packages/alexapyvi alexalogin.py:wqThe container shows as having restarted based on the uptime, and the changes are still there after reconnect so I’m not sure why they aren’t being used. Any ideas?
Other things I’ve tried:
Reproducing the exchange token request in RestFox, all seems to work as expected and the
x-acbuktoken is one of the 5 cookies returned.Writing a short python script (locally, not in HA container) to check
filter_cookiesis returning the cookie for what should be the inputs being used. Also seems to return as expected.If I can’t get the
alexalogin.pychanges to take effect, next thing I can think to try is to expand the test script to a full request to/api/bootstrapand see if it uses the cookies.