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

alexaapi.get_last_device_serial: AttributeError occurred. Arguments: ("'str' object has no attribute 'get'",) #1982

Closed igreg closed 1 year ago

igreg commented 1 year 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

Alexa Media Player fails to find devices after a configuration is setup

To Reproduce

  1. Setup a new configuration
  2. Entered my configuration (email, password, region=amazon.co.uk, my built-in 2FA secret)
  3. Click Submit to validate config
  4. Verify 2FA code is valid / in-sync with 2FA app
  5. Login via amazon.co.uk / pass 2FA step
  6. Configuration is added to HA but fails to discover devices

Expected behavior

I would expect the custom component to find and list devices if has found, registered to my Alexa/Amazon account.

Screenshots

Screenshot 2023-07-14 at 23 49 04

System details

Logs Please provide logs.

I observe the following logs & errors in home-assistant.log

2023-07-14 23:36:45.490 DEBUG (MainThread) [alexapy.alexalogin] Logged in as g*****y@i*********k to amazon.co.uk with id: A1NTWF2GWBYCPB
2023-07-14 23:36:45.722 DEBUG (MainThread) [alexapy.alexalogin] Domain amazon.co.uk matches reported account domain: https://www.amazon.co.uk
2023-07-14 23:36:45.725 DEBUG (MainThread) [alexapy.alexalogin] Login confirmed for g*****y@i*********k - amazon.co.uk; saving cookie to /config/.storage/alexa_media.g*****y@i*********k.pickle
2023-07-14 23:36:45.728 DEBUG (MainThread) [custom_components.alexa_media] Testing login status: {'login_successful': True}
2023-07-14 23:36:45.729 DEBUG (MainThread) [custom_components.alexa_media] Setting up Alexa devices for g*****y@i*********k
2023-07-14 23:36:46.145 DEBUG (MainThread) [custom_components.alexa_media] g*****y@i*********k: Websocket created: <alexapy.alexawebsocket.WebsocketEchoClient object at 0x7f8ae04710>
2023-07-14 23:36:46.145 DEBUG (MainThread) [alexapy.alexawebsocket] Connecting to wss://dp-gw-na.amazon.co.uk/tcomm/ with {'Cookie': '...'}
2023-07-14 23:36:46.536 DEBUG (MainThread) [custom_components.alexa_media] g*****y@i*********k: Websocket successfully connected
2023-07-14 23:36:46.536 DEBUG (MainThread) [custom_components.alexa_media] g*****y@i*********k: Creating coordinator
2023-07-14 23:36:46.536 DEBUG (MainThread) [custom_components.alexa_media] g*****y@i*********k: Refreshing coordinator
2023-07-14 23:36:46.537 DEBUG (MainThread) [alexapy.alexawebsocket] Starting message parsing loop.
2023-07-14 23:36:46.567 DEBUG (MainThread) [alexapy.alexawebsocket] Received raw WebSocket: b'0x37a1b607 0x0000009c {"protocolName":"A:F","parameters":{"AlphaProtocolHandler.maxFragmentSize":"16000","AlphaProtocolHandler.receiveWindowSize":"16"}}TUNE'
2023-07-14 23:36:46.568 DEBUG (MainThread) [alexapy.alexawebsocket] Encoding WebSocket Handshake MSG.
2023-07-14 23:36:46.568 DEBUG (MainThread) [alexapy.alexawebsocket] 0xfe88bc52 0x0000009c {"protocolName":"A:F","parameters":{"AlphaProtocolHandler.receiveWindowSize":"16","AlphaProtocolHandler.maxFragmentSize":"16000"}}TUNE
2023-07-14 23:36:46.573 DEBUG (MainThread) [alexapy.alexawebsocket] A:F Initialization Msg 2 sent: 307866653838626335322030783030303030303963207b2270726f746f636f6c4e616d65223a22413a46222c22706172616d6574657273223a7b22416c70686150726f746f636f6c48616e646c65722e7265636569766557696e646f7753697a65223a223136222c22416c70686150726f746f636f6c48616e646c65722e6d6178467261676d656e7453697a65223a223136303030227d7d54554e45
2023-07-14 23:36:46.644 DEBUG (MainThread) [alexapy.alexawebsocket] Encoding Gateway Register MSG.
2023-07-14 23:36:46.647 DEBUG (MainThread) [alexapy.alexawebsocket] bytearray(b'MSG\x00\x00\x03b\'\xd6\xa2\xc0f\x00\x00\x00\x01:\xa9\xe1\x97\x00\x00\x00\xe4GWM MSG 0x0000b479 0x0000003b urn:tcomm-endpoint:device:deviceType:0:deviceSerialNumber:0 0x00000041 urn:tcomm-endpoint:service:serviceName:DeeWebsiteMessagingService {"command":"REGISTER_CONNECTION"}FABE')
2023-07-14 23:36:46.648 DEBUG (MainThread) [alexapy.alexawebsocket] A:F Initialization Msg 3 (Register Connection) sent: 4d53470000036227d6a2c066000000013aa9e197000000e447574d204d5347203078303030306234373920307830303030303033622075726e3a74636f6d6d2d656e64706f696e743a6465766963653a646576696365547970653a303a64657669636553657269616c4e756d6265723a3020307830303030303034312075726e3a74636f6d6d2d656e64706f696e743a736572766963653a736572766963654e616d653a446565576562736974654d6573736167696e6753657276696365207b22636f6d6d616e64223a2252454749535445525f434f4e4e454354494f4e227d46414245
2023-07-14 23:36:46.699 DEBUG (MainThread) [alexapy.alexawebsocket] Encoding PING.
2023-07-14 23:36:46.701 DEBUG (MainThread) [alexapy.alexawebsocket] bytearray(b"MSG\x00\x00\x00e\'\xd6\xa2\xc1f\x00\x00\x00\x01\xdd3\xb4f\x00\x00\x00=PIN\x00\x00\x00\x00\x00\x00\x01\x89V\x8c\xaa\xec\x00\x00\x00\x07\x00R\x00e\x00g\x00u\x00l\x00a\x00rFABE")
2023-07-14 23:36:46.703 DEBUG (MainThread) [alexapy.alexawebsocket] Send First Ping: 4d53470000006527d6a2c16600000001dd33b4660000003d50494e0000000000000189568caaec000000070052006500670075006c0061007246414245
2023-07-14 23:36:46.725 DEBUG (MainThread) [alexapy.alexaapi] g*****y@i*********k: static GET: https://alexa.amazon.co.uk/api/bootstrap returned 200:OK:application/json
2023-07-14 23:36:46.757 DEBUG (MainThread) [alexapy.alexaapi] g*****y@i*********k: static GET: https://alexa.amazon.co.uk/api/dnd/device-status-list returned 200:OK:application/json
2023-07-14 23:36:46.784 DEBUG (MainThread) [alexapy.alexaapi] g*****y@i*********k: static GET: https://alexa.amazon.co.uk/api/phoenix returned 200:OK:application/json
2023-07-14 23:36:46.789 DEBUG (MainThread) [alexapy.alexawebsocket] Received raw WebSocket: b'MSG\x00\x00\x00eA\x1b\xd0pf\x00\x00\x00\x01"gc\x80\x00\x00\x00=PON\x00\x00\x00\x00\x00\x00\x01\x89V\x8c\xaa\xec\x00\x00\x00\x07\x00R\x00e\x00g\x00u\x00l\x00a\x00rFABE'
2023-07-14 23:36:46.815 DEBUG (MainThread) [alexapy.alexaapi] g*****y@i*********k: get_network_details response: ...
2023-07-14 23:36:46.878 DEBUG (MainThread) [alexapy.alexaapi] g*****y@i*********k: static GET: https://alexa.amazon.co.uk/api/bluetooth?cached=false returned 200:OK:application/json
2023-07-14 23:36:46.907 DEBUG (MainThread) [alexapy.alexaapi] g*****y@i*********k: static GET: https://alexa.amazon.co.uk/api/devices-v2/device returned 200:OK:application/json
2023-07-14 23:36:46.971 DEBUG (MainThread) [alexapy.alexaapi] g*****y@i*********k: static GET: https://alexa.amazon.co.uk/api/device-preferences returned 200:OK:application/json
2023-07-14 23:36:46.972 DEBUG (MainThread) [custom_components.alexa_media] Alexa entities have been loaded. Prepared for discovery.
2023-07-14 23:44:50.764 DEBUG (MainThread) [custom_components.alexa_media] Finished fetching alexa_media data in 5.280 seconds (success: False)
2023-07-14 23:44:50.765 DEBUG (MainThread) [alexapy.alexawebsocket] Received raw WebSocket: b'MSG\x00\x00\x03b?\xfd\x88\xadf\x00\x00\x00\x01/+>\xbf\x00\x00\x02)GWM MSG 0x0000b479 0x0000005c urn:tcomm-endpoint:service:serviceName:DeeWebsiteMessagingService:domain:prod:realm:USAmazon 0x00000080 urn:tcomm-endpoint:device:customerId:A1NTWF2GWBYCPB:deviceType:A2IVLV5VM2W81:deviceSerialNumber:7bd22686b234070361f8c9f0a146702b {"command":"PUSH_VOLUME_CHANGE","payload":"{\\"destinationUserId\\":\\"A1NTWF2GWBYCPB\\",\\"dopplerId\\":{\\"deviceType\\":\\"A2EZ3TS0L1S2KV\\",\\"deviceSerialNumber\\":\\"a151d0be95424228af89780239a7ebbd\\"},\\"volumeSetting\\":26,\\"isMuted\\":false}","timeStamp":1689374685431}FABE'
2023-07-14 23:44:50.765 DEBUG (MainThread) [custom_components.alexa_media] g*****y@i*********k: Received websocket command: PUSH_VOLUME_CHANGE : {'destinationUserId': 'A**********CPB', 'dopplerId': {'deviceType': 'A2EZ3TS0L1S2KV', 'deviceSerialNumber': 'a****************************bbd'}, 'volumeSetting': 26, 'isMuted': False}
2023-07-14 23:44:50.765 DEBUG (MainThread) [custom_components.alexa_media] Adding PUSH_VOLUME_CHANGE to seen_commands: {'PUSH_EQUALIZER_STATE_CHANGE': 1689374685.484014}
2023-07-14 23:44:50.766 DEBUG (MainThread) [custom_components.alexa_media] Discovered new media_player a151d0be95424228af89780239a7ebbd
2023-07-14 23:45:00.909 DEBUG (MainThread) [alexapy.alexaapi] g*****y@i*********k: static GET: https://alexa.amazon.co.uk/api/bootstrap returned 200:OK:application/json
2023-07-14 23:45:00.966 DEBUG (MainThread) [alexapy.alexaapi] g*****y@i*********k: static GET: https://alexa.amazon.co.uk/api/dnd/device-status-list returned 200:OK:application/json
2023-07-14 23:45:01.002 DEBUG (MainThread) [alexapy.alexaapi] g*****y@i*********k: static GET: https://alexa.amazon.co.uk/api/devices-v2/device returned 200:OK:application/json
2023-07-14 23:45:01.029 DEBUG (MainThread) [alexapy.alexaapi] g*****y@i*********k: static GET: https://alexa.amazon.co.uk/api/bluetooth?cached=false returned 200:OK:application/json
2023-07-14 23:45:01.134 DEBUG (MainThread) [alexapy.alexaapi] g*****y@i*********k: static GET: https://alexa.amazon.co.uk/api/device-preferences returned 200:OK:application/json
2023-07-14 23:45:01.135 DEBUG (MainThread) [custom_components.alexa_media] g*****y@i*********k: Found 9 devices, 9 bluetooth
2023-07-14 23:45:05.440 DEBUG (MainThread) [alexapy.alexaapi] g*****y@i*********k: static GET: https://alexa.amazon.co.uk/api/notifications returned 200:OK:application/json
2023-07-14 23:45:05.441 DEBUG (MainThread) [custom_components.alexa_media] g*****y@i*********k: Updated 2 notifications for 3 devices at 2023-07-14 23:45:05.441474+01:00
2023-07-14 23:45:05.613 DEBUG (MainThread) [alexapy.alexaapi] g*****y@i*********k: static GET: https://alexa.amazon.co.uk/api/activities?startTime=&size=10&offset=1 returned 200:OK:application/json
2023-07-14 23:45:05.614 WARNING (MainThread) [alexapy.helpers] alexaapi.get_last_device_serial((<alexapy.alexalogin.AlexaLogin object at 0x7f5e20b0d0>,), {}): An error occurred accessing AlexaAPI: An exception of type AttributeError occurred. Arguments:
("'str' object has no attribute 'get'",)
2023-07-14 23:45:05.616 DEBUG (MainThread) [custom_components.alexa_media] Finished fetching alexa_media data in 4.850 seconds (success: False)

Additional context

babanu5 commented 1 year ago

Hi, can somebody answer this? I have the same issue and is has been bugging me for the past 2 weeks!

github-actions[bot] commented 1 year ago

This bug report has been labelled as help wanted since there has been no activity in the last 3 weeks. It will not be closed automatically.

ukgrant commented 1 year ago

Not sure if this will help someone, but I encountered a similar issue and resolved by manually creating the following directory: config/www/alexa_tts

I then removed and re-added the integration.

tplas commented 1 year ago

Wow! That did indeed do the trick, to create that folder. Nice magic incantation there.

Even better, it found all my old devices & hooked them back up to my automations. I had resigned myself to needing to re-enter all of those after they had gotten lost on my AMP HACS integration version updatee.

Thank you!

JaySpec1488 commented 1 year ago

Not sure if this will help someone, but I encountered a similar issue and resolved by manually creating the following directory: config/www/alexa_tts

I then removed and re-added the integration.

What do you mean with "creating a directory" where and how? πŸ˜…

ukgrant commented 1 year ago

@JaySpec1488 There's a few ways you can do this and it will depend on your installation type. I am using home assistant OS, so used the addon store to install the "file editor". Using the file editor, create a folder called "www" (if it doesn't already exist) then inside that create a folder called "alexa_tts"

JaySpec1488 commented 1 year ago

@JaySpec1488 There's a few ways you can do this and it will depend on your installation type. I am using home assistant OS, so used the addon store to install the "file editor". Using the file editor, create a folder called "www" (if it doesn't already exist) then inside that create a folder called "alexa_tts"

Mhh, seems like that i already have this folder... so i have another issue that the integration finds nothing. But my log says something about that... crazy... πŸ™ƒ But thank you. Screenshot_20230918_080931_Home Assistant @

JaySpec1488 commented 1 year ago

@JaySpec1488 There's a few ways you can do this and it will depend on your installation type. I am using home assistant OS, so used the addon store to install the "file editor". Using the file editor, create a folder called "www" (if it doesn't already exist) then inside that create a folder called "alexa_tts"

Screenshot_20230918_082504_Home Assistant

ukgrant commented 1 year ago

@JaySpec1488 You have created in the wrong place. config/config/www/alexa_tts should be config/www/alexa_tts.

Also I think the latest version just released v4.7.1 resolves this issue anyway, so can try updating or removing & reinstalling.

zimpower commented 1 year ago

Not sure if this will help someone, but I encountered a similar issue and resolved by manually creating the following directory: config/www/alexa_tts

I then removed and re-added the integration.

I am am v4.7.1 and still had the issue. This solution also worked for me. Thanks!

Speedafix commented 1 year ago

YEAAAAH it works with the Folder THANKS

JaySpec1488 commented 1 year ago

Not sure if this will help someone, but I encountered a similar issue and resolved by manually creating the following directory: config/www/alexa_tts I then removed and re-added the integration.

I am am v4.7.1 and still had the issue. This solution also worked for me. Thanks!

Nice. That worked for me too πŸ‘πŸ‘πŸ‘πŸ‘πŸ˜πŸ˜πŸ˜

JaySpec1488 commented 1 year ago

@JaySpec1488 You have created in the wrong place. config/config/www/alexa_tts should be config/www/alexa_tts.

Also I think the latest version just released v4.7.1 resolves this issue anyway, so can try updating or removing & reinstalling.

Yes. I changed it. Now it works. Thx πŸ‘πŸ‘πŸ‘πŸ˜πŸ˜πŸ˜

Mauley commented 1 year ago

Not sure if this will help someone, but I encountered a similar issue and resolved by manually creating the following directory: config/www/alexa_tts I then removed and re-added the integration.

What do you mean with "creating a directory" where and how? πŸ˜…

This is so strange, but helped.. Thanks a lot!