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:

image

To Reproduce

  1. Remove the AMP integration
  2. Re-add the AMP integration setting the amazon region to amazon.co.uk
  3. Login to amazon through the proxy page
  4. 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

image

System details

  • Home-assistant (version): 2024.8.1
  • alexa_media (version from const.py or HA startup): 4.12.7
  • alexapy (version from pip show alexapy or 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:

  1. Add the AMP integration but using the amazon.com region.
  2. Once logged in to amazon, the AMP integration will be added, but will fail to start. image
  3. Click the 3 dot menu for the failing entry and select “System options”
  4. Turn off both options and save: image
  5. Click “Add entry” and complete the setup this time for amazon.co.uk region image
  6. The integration should add successfully, but will then prompt to be re-configured: image
  7. Remove the amazon.com entry.

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)

Most upvoted comments

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! … <#m_1798710548594273036_> On Sun, 1 Sept 2024 at 11:09, David Miller @.> wrote: 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? — Reply to this email directly, view it on GitHub <#2469 (comment) https://github.com/alandtse/alexa_media_player/issues/2469#issuecomment-2323268298>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABFWRDXL7DFW4LLQ7JKWVLDZULRUHAVCNFSM6AAAAABMWPTCBWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMRTGI3DQMRZHA https://github.com/notifications/unsubscribe-auth/ABFWRDXL7DFW4LLQ7JKWVLDZULRUHAVCNFSM6AAAAABMWPTCBWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMRTGI3DQMRZHA . You are receiving this because you are subscribed to this thread.Message ID: @.>

The only thing “sure” (for now) you can do is disable system options, like this:

image.png (view on web) https://github.com/user-attachments/assets/3731c259-120d-423a-a76d-36ac421b75b6

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

I’m pretty sure it’s affecting thousands!

On Sun, 1 Sept 2024 at 11:09, David Miller @.***> wrote:

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?

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

Could you try this:

  • Delete the integration’s config entry
  • Delete /config/,storage/alexa_media.<your_email>.pickle
  • In HACS, delete the custom_component and restart HA
  • In HACS, install Alexa Media Player custom component v4.12.8
  • Restart HA
  • in ssh/terminal session:
    • docker exec -it homeassistant bash
    • cd /usr/local/lib/python3.12/http
    • cd ../site-packages/alexapy
    • This adds alexapy merge request !380 which contains the corresponding async def delete_cookiefile(self) which AMP 4.12.8 will call to delete the pickle file when removing the config entry.
  • Restart HA
  • Clear browser cookies & cached files
  • Try adding the integration with:
    • Seconds between scans 360 - with http2push active, this effectively becomes 1 hour (3600 seconds)
    • For now, do not enable Include devices connected via Echo
  • Verify at this point that the integration is successfully configured
  • Three dots System options
    • Disable Enable newly added entities but leave Enable polling for updates enabled

Need to see debug log trace for alexapy, authcaptureproxy and alexa_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.

2024-08-20 10:56:50.146 DEBUG (MainThread) [alexapy.alexalogin] 5 cookies successfully exchanged for refresh token for domain .amazon.de
2024-08-20 10:56:50.147 DEBUG (MainThread) [alexapy.alexalogin] Attempting to discover CSRF token
2024-08-20 10:56:50.254 DEBUG (MainThread) [alexapy.alexalogin] CSRF token not found from /spa/index.html
2024-08-20 10:56:50.459 DEBUG (MainThread) [alexapy.alexalogin] CSRF token not found from /api/devices-v2/device?cached=false
2024-08-20 10:56:50.518 DEBUG (MainThread) [alexapy.alexalogin] CSRF token not found from /templates/oobe/d-device-pick.handlebars
2024-08-20 10:56:50.568 DEBUG (MainThread) [alexapy.alexalogin] No csrf token found
2024-08-20 10:56:50.866 DEBUG (MainThread) [alexapy.alexalogin] GET:
https://alexa.amazon.com/api/bootstrap returned 200:OK with response <CIMultiDictProxy('Content-Type': 'application/json', 'Content-Length': '171', 'Connection': 'keep-alive', 'Server': 'Server', 'Date': 'Tue, 20 Aug 2024 08:56:50 GMT', 'x-amz-rid': '6KKHP4FZ41X4BCB9HTB6', 'Set-Cookie': 'csrf=30060786; expires=Sun, 20-Aug-2034 08:56:50 GMT; Domain=.amazon.com; Path=/', 'x-amzn-RequestId': '6KKHP4FZ41X4BCB9HTB6', 'x-amzn-alt-domain': 'https://alexa.amazon.de/logout', 'Vary': 'Content-Type,Accept-Encoding,User-Agent', 'X-Cache': 'Miss from cloudfront', 'Via': '1.1 918126cde448a82c2757fd37058ea3ec.cloudfront.net (CloudFront)', 'X-Amz-Cf-Pop': 'HAM50-C1', 'X-Amz-Cf-Id': 'iO606tajoBCwq-Th8kkZq5uCE5wd6oikuf2eMvoQSlz_thiO78utvg==')>
2024-08-20 10:56:50.919 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, 20 Aug 2024 08:56:50 GMT', 'Strict-Transport-Security': 'max-age=0; includeSubDomains;', 'x-amz-rid': 'Y477TQPNJ78YCCZWW972', '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': 'Y477TQPNJ78YCCZWW972', 'Vary': 'Content-Type,Accept-Encoding,User-Agent', 'X-Cache': 'Error from cloudfront', 'Via': '1.1 eabf0052502240e2b09c2e962490cabc.cloudfront.net (CloudFront)', 'X-Amz-Cf-Pop': 'HAM50-P1', 'X-Amz-Cf-Id': '-PQKFYqt386Wb4iwH8OjLJsELQZkdVXwXQyUcQujr8-7eTfUZivdVQ==')>
2024-08-20 10:56:50.920 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=foo; lc-main=de_DE; sess-at-main="\\"b9BhEQzsyFcjYE/PA63XLpaDdONUfxzIgr+6vpYGL8E=\\""; session-id=257-9085617-4147239; session-id-time=2354864210l; session-token=bar; sid="\\"NPowU5s/wYMuNgqu4a7Dfg==|Sw777im+40ufbBsvCgpED22f/VD0l8vNEXo7L+h+hAE=\\""; ubid-acbde=135-3594605-4904817; ubid-main=135-3594605-4904817; x-main="\\"XDSi40t1MtVOVBV8nTfUOpNBgcWl?PaQ\\""')>, real_url=URL('https://alexa.amazon.de/api/bootstrap')), ())
async def delete_cookiefile(self) is now merged in alexapy 1.29.0 so you can just edit AMP's manifest.json from 1.28.2 to 1.29.0.

tried this already as well.

HA 2024.8.2 AMP v4.12.10

@jleinenbach pip show aiohttp is 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.de for the region? Based on the x-acbuk cookie name, this may be an amazon.co.uk specific issue. amazon.com doesn’t seem to have the same problem.


I made some adjustments to the logging in alexalogin.py using the steps mentioned by @danielbrunt57 to try get some more diagnostics (adjusting some existing messages and adding output of filter_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 alexapy seems to indicate it is the correct location so I’m not sure what is happening.

I don’t have any other version of alexalogin.py in the alexapy directory. The steps I’m using:

  1. SSH to HassOS Advanced SSH addon
  2. docker exec -it homeassistant bash
  3. cd /usr/local/lib/python3.12/site-packages/alexapy
  4. vi alexalogin.py
  5. Edit file and then exit using :wq
  6. Restart HA

The 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-acbuk token is one of the 5 cookies returned.

  • Writing a short python script (locally, not in HA container) to check filter_cookies is returning the cookie for what should be the inputs being used. Also seems to return as expected.

    import aiohttp
    import asyncio
    from http.cookies import SimpleCookie
    from yarl import URL
    
    async def main():
    
        async with aiohttp.ClientSession() as session:
            raw_cookie = SimpleCookie()
            cookie_name = "x-acbuk"
            cookie_value = "\"<REDACTED>\""
            raw_cookie[cookie_name] = (
                cookie_value
                if not (
                    cookie_value.startswith('"') and cookie_value.endswith('"')
                )
                # Strings are returned within quotations, strip them
                else cookie_value[1:-1]
            )
            raw_cookie[cookie_name]["domain"] = ".amazon.co.uk"
            raw_cookie[cookie_name]["path"] = "/"
            raw_cookie[cookie_name]["secure"] = True
            raw_cookie[cookie_name]["expires"] = "14 Aug 2044 15:57:18 GMT"
            raw_cookie[cookie_name]["httpOnly"] = False
    
            session.cookie_jar.update_cookies(raw_cookie, URL(".amazon.co.uk"))
            cookies = session.cookie_jar.filter_cookies(URL("https://alexa.amazon.co.uk/api/bootstrap"))
            print("Test") # Debugger breakpoint here...
    
    asyncio.run(main())
    

If I can’t get the alexalogin.py changes to take effect, next thing I can think to try is to expand the test script to a full request to /api/bootstrap and see if it uses the cookies.