Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NO DEVICES FOUND: api/phoenix repeatedly returns 429:Too Many Requests resulting in CancelledError & failure to get network details #2702

Open
Pingfragger opened this issue Nov 28, 2024 · 44 comments
Assignees
Labels
amazonissue Issue needs to have a change made by Amazon

Comments

@Pingfragger
Copy link

Pingfragger commented Nov 28, 2024

Describe the bug

The Alexa Media Player integration is experiencing issues with region mismatch and API errors. When using amazon.de, no devices are found, and API errors occur. Switching to amazon.com lists devices but they cannot be controlled.

To Reproduce

The integration fails to authenticate properly with amazon.de, resulting in no devices being listed and API errors. When switching to amazon.com, devices appear but cannot be controlled, with logs showing domain mismatch errors between amazon.com and amazon.de.

  • Configure Alexa Media Player with amazon.de
  • Observe that no devices are found and API errors occur.
  • Switch to amazon.com.
  • Devices are found but cannot be controlled; logs show domain mismatch errors.

Expected behavior

Devices should be discoverable and controllable using my Amazon region (amazon.de), without domain mismatch or authentication issues.

Screenshots

Login:
Desktop Screenshot 2024 11 28 - 22 28 04 72

Errors after login (amazon.de)
Desktop Screenshot 2024 11 28 - 22 31 20 89
Desktop Screenshot 2024 11 28 - 22 31 26 11
Screenshot_20241129_060352_Home Assistant

Errors after login (amazon.de) with Set async_timeout to 300
Desktop Screenshot 2024 11 28 - 22 59 13 66
Desktop Screenshot 2024 11 28 - 22 59 16 92

Error after login (amazon.com)
Desktop Screenshot 2024 11 28 - 22 43 48 36

Result of login in amazon.de and amazon.com
Desktop Screenshot 2024 11 28 - 22 45 20 59

System details

Home Assistant version: Core 2024.11.3 - Supervisor 2024.11.4 - Operating System 13.2 - Frontend 20241106.2
alexa_media version: 4.13.7, 4.13.8 and 5.0.0 tested
alexapy version: 1.29.4
Is Amazon [2FA/2SV enabled]: Yes
Amazon Domain: amazon.de

Debug Logs (alexa_media & alexapy)

home-assistant_2024-11-28T22-18-34.509Z.log

Additional context

What I already tried:

  • Tried different versions of alexa_media
  • Installed alexa_media on another HA system (version 2024.9.1) with the same error.
  • Accessing https://alexa.amazon.com/api/devices-v2/device and https://alexa.amazon.de/api/devices-v2/device in a browser shows Alexa devices for both.
  • OpenHAB with Echo Control Binding (similar to Alexa Media Player) works without API issues; login and devices function correctly.
  • Disabled all Echo devices, Alexa apps, integrations/bindings for at least 12 hours due to "Too Many Requests" error, but same even after 12 hours
  • Tried various login options over three days.
  • Set async_timeout to 300; then encountered "Too Many Requests" error.
  • Changed code in manifest.json "requirements": ["alexapy>=1.28.2", "packaging>=20.3", "wrapt>=1.14.0"],
  • Tried putting the local HA-URL in the public URL
  • Include only one Alexa device in the config
  • Tried disabling the 2FA
  • Deleting all logged in devices in the the Alexa app

All of this did not work

It worked to integrate my wife's account (Amazon.de without 2FA). The devices appear there

Assumption:
The problem might accur due to the number of devices in my account (Total about 110 devices - Echos and some sensors via the xiaomi skill). The devices cannot be deleted from the alexa app - > unknown error

@Git-Vi
Copy link

Git-Vi commented Dec 1, 2024

I have faced same issue:

  • Home assistant docker container - 2024.11.3
  • Alexa Media Player 5.0 (all recorders are removed from HA configuration file )
  • all entities are unavailable after the account sync. Amazon account from DE but it possible to add only with COM

@danielbrunt57
Copy link
Collaborator

I have faced same issue:

  • Home assistant docker container - 2024.11.3
  • Alexa Media Player 5.0 (all recorders are removed from HA configuration file )
  • all entities are unavailable after the account sync. Amazon account from DE but it possible to add only with COM

Where are your devices registered? www.amazon.com or .de?

Mine originally were registered in Amazon.com as that is where I bought my first echo. Since then, I've moved them to amazon.ca, then back to .com and earlier this year back to .ca (all moves were to gain access to skills only available in .com or in .ca).

You have to use the domain where they are registered. Using another domain is pointless as it will fail to see them.

If they are in .de, use .de. If that fails at some point, that failure needs to be investigated and fixed. Trying to add the integration with another domain will only succeed in authenticating and initial setup with the cookie but will fail to see devices.

@Git-Vi
Copy link

Git-Vi commented Dec 5, 2024

I have faced same issue:

  • Home assistant docker container - 2024.11.3
  • Alexa Media Player 5.0 (all recorders are removed from HA configuration file )
  • all entities are unavailable after the account sync. Amazon account from DE but it possible to add only with COM

Where are your devices registered? www.amazon.com or .de?

Mine originally were registered in Amazon.com as that is where I bought my first echo. Since then, I've moved them to amazon.ca, then back to .com and earlier this year back to .ca (all moves were to gain access to skills only available in .com or in .ca).

You have to use the domain where they are registered. Using another domain is pointless as it will fail to see them.

If they are in .de, use .de. If that fails at some point, that failure needs to be investigated and fixed. Trying to add the integration with another domain will only succeed in authenticating and initial setup with the cookie but will fail to see devices.

all my devices are registered n Amazon.de
before the update I had in my configuration.yaml

#AlexaSkill     
alexa:
  smart_home:
    locale: de-DE
    endpoint: https://api.eu.amazonalexa.com/v3/events
    client_id: https://layla.amazon.com/
    client_secret: !secret AlexaSkill_client_secret

if I am not mistaken it was Amazon alexa 4.8.12

@Git-Vi
Copy link

Git-Vi commented Dec 5, 2024

I made it work

  1. the newest version was installed 5.0.1
  2. use my account and domain amazon.de
  3. Alexa Media Player - Configuration - put email and password, left field Built 2FA empty
  4. was redirected to a amazon page to confirm the account
  5. back to HA and everything works now

@danielbrunt57
Copy link
Collaborator

all my devices are registered in Amazon.de
before the update I had in my configuration.yaml

#AlexaSkill     
alexa:
  smart_home:
    locale: de-DE
    endpoint: https://api.eu.amazonalexa.com/v3/events
    client_id: https://layla.amazon.com/
    client_secret: !secret AlexaSkill_client_secret

FYI, that entry is not for Alexa Media Player.
It's for the Amazon Alexa Smart Home Skill

@Pingfragger
Copy link
Author

@danielbrunt57 Please open the issue again.
The problem is not solved and hat nothing to to with the alexapy version.
It is an API / "Too Many Requests" error.

@danielbrunt57 danielbrunt57 changed the title Region Mismatch and API Errors No devices are found when using amazon.de: API errors: "Too Many Requests" Dec 6, 2024
@danielbrunt57 danielbrunt57 reopened this Dec 6, 2024
@danielbrunt57
Copy link
Collaborator

@Pingfragger Can you provide a log trace from beginning:

2024-12-06 00:29:42.103 DEBUG (ImportExecutor_0) [alexapy.alexalogin] http.cookies patch: Morsel._reserved: {'partitioned': 'Partitioned'}; Morsel._flags: {'httponly', 'partitioned', 'secure'}
2024-12-06 00:29:42.515 DEBUG (MainThread) [custom_components.alexa_media] Nothing to import from configuration.yaml, loading from Integrations
2024-12-06 00:29:42.516 DEBUG (MainThread) [custom_components.alexa_media]
-------------------------------------------------------------------
alexa_media
Version: 5.0.1
This is a custom component
If you have any issues with this you need to open an issue here:
https://github.com/alandtse/alexa_media_player/issues
-------------------------------------------------------------------

through to the point of failure?

Make sure you've enabled debug for:

  • alexapy
  • authcaptureproxy
  • custom_components.alexa_media

httpx may be useful as well.

logger:

#  default: debug
#  default: critical
#  default: fatal
#  default: error
#  default: warning
  default: warn
#  default: info
#  default: notset
  logs:
    alexapy: debug
    authcaptureproxy: debug
#    bellows.zigbee.application: debug
#    bellows.ezsp: debug
    custom_components.alexa_media: debug
#    custom_components.battery_notes: info
#    custom_components.ble_monitor: info
#    custom_components.custom-ui: debug
#    custom_components.entity_controller: debug
#    custom_components.entity_controller.fireplace_light_control: debug
#    custom_components.fordpass: debug
#    custom_components.hacs: error
#    custom_components.hyperion: debug
#    aiogitgubapi: debug
#    custom_components.hass_agent_notifier: debug
#    custom_components.homeseer: debug
#    custom_components.magic_areas: debug
#    custom_components.neviweb: debug
#    custom_components.patch: debug
#    google.cloud.pubsub_v1: debug
#    google.cloud.pubsub_v1.subscriber._protocol.leaser: debug
#    google_nest_sdm: debug
#    google_nest_sdm.device: debug
#    google_nest_sdm.google_nest_subscriber: debug
#    google_nest_sdm.event: debug
#    google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager: debug
#    hacs: debug
#    hass_nabucasa: debug
    httpx: debug
#    hyperion: debug
#    snitun: debug
#    homeassistant.components.switch: warn
#    homeassistant.components.life360.device_tracker: debug
#    homeassistant.components.mqtt: warn
#    homeassistant.components.nest: debug
#    homeassistant.components.nest.sensor_sdm: debug
#    homeassistant.components.recorder: info
#    homeassistant.components.http.ban: debug
#    homeassistant.components.rest: info
#    homeassistant.components.traccar.device_tracker: debug
#    homeassistant.components.zha: debug
#    homeassistant.components.webhook: debug
#    homeassistant.core: debug
#    pyhs3: debug
#    queueman: debug
#    zigpy: debug
#    zigpy_cc: debug
#    zigpy_deconz.zigbee.application: debug
#    zigpy_deconz.api: debug
#    zigpy_xbee.zigbee.application: debug
#    zigpy_xbee.api: debug
#    zigpy_zigate: debug
#    zhaquirks: debug

@Pingfragger
Copy link
Author

I have enabled the debug logging as requested and gathered logs from the beginning to the point of failure. The logs include detailed traces for alexapy, authcaptureproxy, custom_components.alexa_media, and httpx. You can find the full logs attached here:
home-assistant_alexa_media_2024-12-06T23-28-52.428Z.log

Please let me know if further details are needed or how to proceed.

@danielbrunt57
Copy link
Collaborator

danielbrunt57 commented Dec 7, 2024

You can find the full logs attached here:

The logs show the phoenix call is failing and might seem to be related to Alexa guard?

2024-12-07 00:27:49.191 DEBUG (MainThread) [alexapy.alexaapi] d********7@g*******m: static GET: https://alexa.amazon.de/api/phoenix returned 429:Too Many Requests:application/json
2024-12-07 00:27:49.191 DEBUG (MainThread) [alexapy.alexaapi] api_calls: 7

2024-12-07 00:27:49.192 INFO (MainThread) [alexapy.alexaapi] Backing off _static_request(...) for 2.0s (alexapy.errors.AlexapyTooManyRequestsError: Too Many Requests)
2024-12-07 00:27:51.265 DEBUG (MainThread) [alexapy.alexaapi] d********7@g*******m: static GET: https://alexa.amazon.de/api/phoenix returned 429:Too Many Requests:application/json
2024-12-07 00:27:51.265 DEBUG (MainThread) [alexapy.alexaapi] api_calls: 8

2024-12-07 00:27:51.266 INFO (MainThread) [alexapy.alexaapi] Backing off _static_request(...) for 4.0s (alexapy.errors.AlexapyTooManyRequestsError: Too Many Requests)
2024-12-07 00:27:55.350 DEBUG (MainThread) [alexapy.alexaapi] d********7@g*******m: static GET: https://alexa.amazon.de/api/phoenix returned 429:Too Many Requests:application/json
2024-12-07 00:27:55.350 DEBUG (MainThread) [alexapy.alexaapi] api_calls: 9

2024-12-07 00:27:55.350 INFO (MainThread) [alexapy.alexaapi] Backing off _static_request(...) for 8.0s (alexapy.errors.AlexapyTooManyRequestsError: Too Many Requests)
2024-12-07 00:28:03.431 DEBUG (MainThread) [alexapy.alexaapi] d********7@g*******m: static GET: https://alexa.amazon.de/api/phoenix returned 429:Too Many Requests:application/json
2024-12-07 00:28:03.432 DEBUG (MainThread) [alexapy.alexaapi] api_calls: 10

2024-12-07 00:28:03.432 INFO (MainThread) [alexapy.alexaapi] Backing off _static_request(...) for 16.0s (alexapy.errors.AlexapyTooManyRequestsError: Too Many Requests)

2024-12-07 00:28:17.967 WARNING (MainThread) [alexapy.helpers] alexaapi.get_guard_details((<alexapy.alexalogin.AlexaLogin object at 0x7f34681810>,), {}): Timeout error occurred accessing AlexaAPI: An exception of type CancelledError occurred. Arguments:
()
2024-12-07 00:28:17.968 DEBUG (MainThread) [alexapy.alexaapi] d********7@g*******m: get_network_details response: None

The result of a successful phoenix GET is the network details:

2024-12-06 16:40:49.196 DEBUG (MainThread) [alexapy.alexaapi] d****l@b******a: static GET: https://alexa.amazon.ca/api/phoenix returned 200:OK:application/json
2024-12-06 16:40:49.196 DEBUG (MainThread) [alexapy.alexaapi] api_calls: 4
2024-12-06 16:40:49.222 DEBUG (MainThread) [alexapy.alexaapi] d****l@b******a: get_network_details response: 

I've modified my alexa_media/__init__.py removing reference to guard and alarm_control_panel. I saved the edit, remove integration, restarted HA and re-added the integration with no errors. Give it a whirl and see if it makes a difference or not.
__init__.zip

** UPDATE **
It's been reported in another thread that this change doesn't solve the failure due to repeated 429 errors ending in a cancelled error and a failure to get network details. Back to the drawing board...

@danielbrunt57 danielbrunt57 changed the title No devices are found when using amazon.de: API errors: "Too Many Requests" No devices are found when using amazon.de: api/phoenix returned 429:Too Many Requests Dec 7, 2024
@danielbrunt57 danielbrunt57 changed the title No devices are found when using amazon.de: api/phoenix returned 429:Too Many Requests No devices are found (amazon.de): api/phoenix returned 429:Too Many Requests Dec 7, 2024
@Pingfragger
Copy link
Author

I followed the suggested steps, including removing and re-adding the account, restarting Home Assistant, and ensuring the correct region (amazon.de) is used. However, the issue persists. I have attached the new logs for further analysis:
home-assistant_alexa_media_2024-12-07T21-45-14.209Z.log

Please let me know if additional debugging or changes are required.

@danielbrunt57
Copy link
Collaborator

danielbrunt57 commented Dec 8, 2024

The problem is the api/phoenix call is failing:

2024-12-07 22:44:30.250 DEBUG (MainThread) [alexapy.alexaapi] d********7@g*******m: static GET: https://alexa.amazon.de/api/phoenix returned 429:Too Many Requests:application/json

2024-12-07 22:44:30.251 INFO (MainThread) [alexapy.alexaapi] Backing off _static_request(...) for 1.0s (alexapy.errors.AlexapyTooManyRequestsError: Too Many Requests)

2024-12-07 22:44:31.381 INFO (MainThread) [alexapy.alexaapi] Backing off _static_request(...) for 2.0s (alexapy.errors.AlexapyTooManyRequestsError: Too Many Requests)

2024-12-07 22:44:33.613 DEBUG (MainThread) [alexapy.alexaapi] d********7@g*******m: static GET: https://alexa.amazon.de/api/phoenix returned 429:Too Many Requests:application/json

2024-12-07 22:44:33.614 INFO (MainThread) [alexapy.alexaapi] Backing off _static_request(...) for 4.0s (alexapy.errors.AlexapyTooManyRequestsError: Too Many Requests)

2024-12-07 22:44:37.698 DEBUG (MainThread) [alexapy.alexaapi] d********7@g*******m: static GET: https://alexa.amazon.de/api/phoenix returned 429:Too Many Requests:application/json

2024-12-07 22:44:37.699 INFO (MainThread) [alexapy.alexaapi] Backing off _static_request(...) for 8.0s (alexapy.errors.AlexapyTooManyRequestsError: Too Many Requests)

2024-12-07 22:44:45.782 DEBUG (MainThread) [alexapy.alexaapi] d********7@g*******m: static GET: https://alexa.amazon.de/api/phoenix returned 429:Too Many Requests:application/json

2024-12-07 22:44:45.783 INFO (MainThread) [alexapy.alexaapi] Backing off _static_request(...) for 16.0s (alexapy.errors.AlexapyTooManyRequestsError: Too Many Requests)

2024-12-07 22:45:00.074 WARNING (MainThread) [alexapy.helpers] alexaapi.get_guard_details((<alexapy.alexalogin.AlexaLogin object at 0x7f2d6a60d0>,), {}): Timeout error occurred accessing AlexaAPI: An exception of type CancelledError occurred. Arguments:

22:44:45 - 22:44:30 = 15s. The final backoff of 16s does not have time to try again since the overall timeout for the request is 30s and is cancelled at 22:45:00.

The 30-second timeout is defined in custom_components/alexa_media/__init__.py. You can editing the "30" to "60" and retry adding the integration. If the debug logs then show the 5th try after the final 16s delay is still failing with the CancelledError, then alexa guard may truly be defunct now and Amazon is now refusing any request for "guard" details. I would not expect to see a "429: Too Many Requests" error but the overall code is rather convoluted so that may be what percolates to the top. If it is failing due to trying to get guard details, we'll have to remove that from the equation. This is __init__.py with guard removed but still with the 30s timeout: __init__.zip

@Pingfragger
Copy link
Author

I have increased the timeout to 60 seconds in __init__.py and also tried removing references to Alexa Guard and Alarm Control Panel as suggested using your file. Unfortunately, the issue persists, and I am still encountering the same "Too Many Requests" error. I have attached the updated logs for further analysis:
home-assistant_alexa_media_2024-12-08T03-45-55.727Z.log

@danielbrunt57
Copy link
Collaborator

danielbrunt57 commented Dec 8, 2024

After careful analysis, I've discovered that inside alexaapi.py, get_network_details piggybacks onto the get_guard_details function as they are the same /ap/phoenix call (as per comments in the code) and therefore "guard" in the log message is a "red herring" in all of this. The original call is get_network_details but the 429 occurs in the actual "GET" inside get_guard_details. Bottomline is I'm no further ahead is determining why this is repeatedly getting 429: Too Many Requests errors and times out after 30s

2024-12-07 22:45:00.074 WARNING (MainThread) [alexapy.helpers] alexaapi.get_guard_details((<alexapy.alexalogin.AlexaLogin object at 0x7f2d6a60d0>,), {}): Timeout error occurred accessing AlexaAPI: An exception of type CancelledError occurred. Arguments:

I'll keep digging but it's 3 am and I need some shut-eye...

@danielbrunt57 danielbrunt57 changed the title No devices are found (amazon.de): api/phoenix returned 429:Too Many Requests No devices are found (amazon.de): api/phoenix repeatedly returns 429:Too Many Requests resulting in CancelledError thus failure to get network details Dec 8, 2024
@danielbrunt57 danielbrunt57 self-assigned this Dec 8, 2024
@danielbrunt57 danielbrunt57 added the amazonissue Issue needs to have a change made by Amazon label Dec 8, 2024
@Pingfragger
Copy link
Author

Thanks so much for all your hard work!
I started a test and created a new Amazon.de account and added one Echo Dot device to it. I also added 2FA, like I did with the other account that isn't working.
I tried to add both accounts multiple times, and every time, the result was that my main account showed the API error, but the new account always succeeded in connecting and showing the one Echo device.
I included the log from the work account to see if I can figure out what the problem is:
home-assistant_alexa_media_2024-12-08T19-29-55.412Z.log

@danielbrunt57
Copy link
Collaborator

With the assistance of ChatGPT, I've implemented asyncio.Semaphore(5) in class AlexaAPI (file /usr/local/lib/python3.13/site-packages/alexapy/alexaapi.py) as well an await asyncio.sleep(0.5) before the response = await getattr(session, method) in async def _static_request.

I was having one or two "429: Too Many Requests" errors in the async def get_customer_history_records (which would succeed though before the retry limit cancelled it). With the above modification, I'm not seeing any "429" errors now.

Here is the modified file: alexaapi.zip

Keeping my fingers crossed!

@danielbrunt57
Copy link
Collaborator

danielbrunt57 commented Dec 10, 2024

Thanks so much for all your hard work!

You're more than welcome!

I started a test and created a new Amazon.de account and added one Echo Dot device to it. I also added 2FA, like I did with the other account that isn't working. I tried to add both accounts multiple times, and every time, the result was that my main account showed the API error, but the new account always succeeded in connecting and showing the one Echo device. I included the log from the work account to see if I can figure out what the problem is: home-assistant_alexa_media_2024-12-08T19-29-55.412Z.log

In your new account log, the network details is retrieved on API call #2.
In your original account, wasn't that API call like #5 or 6?

2024-12-08 20:29:42.650 DEBUG (MainThread) [alexapy.alexahttp2] Preparing ping to https://alexa.eu.gateway.devices.a2z.com/ping
2024-12-08 20:29:42.932 DEBUG (MainThread) [alexapy.alexaapi] d***********a@g*******m: static GET: https://alexa.amazon.de/api/devices-v2/device returned 200:OK:application/json
2024-12-08 20:29:42.933 DEBUG (MainThread) [alexapy.alexaapi] api_calls: 1
2024-12-08 20:29:42.994 DEBUG (MainThread) [alexapy.alexaapi] d***********a@g*******m: static GET: https://alexa.amazon.de/api/phoenix returned 200:OK:application/json
2024-12-08 20:29:42.995 DEBUG (MainThread) [alexapy.alexaapi] api_calls: 2
2024-12-08 20:29:42.999 DEBUG (MainThread) [alexapy.alexaapi] d***********a@g*******m: get_network_details response: {'locationDetails': {

@Pingfragger
Copy link
Author

Thanks so much for all your hard work! I started a test and created a new Amazon.de account and added one Echo Dot device to it. I also added 2FA, like I did with the other account that isn't working. I tried to add both accounts multiple times, and every time, the result was that my main account showed the API error, but the new account always succeeded in connecting and showing the one Echo device. I included the log from the work account to see if I can figure out what the problem is: home-assistant_alexa_media_2024-12-08T19-29-55.412Z.log

In your new account log, the network details is retrieved on API call #2. In your original account, wasn't that API call like #5 or 6?

2024-12-08 20:29:42.650 DEBUG (MainThread) [alexapy.alexahttp2] Preparing ping to https://alexa.eu.gateway.devices.a2z.com/ping
2024-12-08 20:29:42.932 DEBUG (MainThread) [alexapy.alexaapi] d***********a@g*******m: static GET: https://alexa.amazon.de/api/devices-v2/device returned 200:OK:application/json
2024-12-08 20:29:42.933 DEBUG (MainThread) [alexapy.alexaapi] api_calls: 1
2024-12-08 20:29:42.994 DEBUG (MainThread) [alexapy.alexaapi] d***********a@g*******m: static GET: https://alexa.amazon.de/api/phoenix returned 200:OK:application/json
2024-12-08 20:29:42.995 DEBUG (MainThread) [alexapy.alexaapi] api_calls: 2
2024-12-08 20:29:42.999 DEBUG (MainThread) [alexapy.alexaapi] d***********a@g*******m: get_network_details response: {'locationDetails': {

That is true, but I do not know enough about it to say what it means.

With the assistance of ChatGPT, I've implemented asyncio.Semaphore(5) in class AlexaAPI (file /usr/local/lib/python3.13/site-packages/alexapy/alexaapi.py) as well an await asyncio.sleep(0.5) before the response = await getattr(session, method) in async def _static_request.

I was having one or two "429: Too Many Requests" errors in the async def get_customer_history_records (which would succeed though before the retry limit cancelled it). With the above modification, I'm not seeing any "429" errors now.

Here is the modified file: alexaapi.zip

Keeping my fingers crossed!

Where can I find the alexaapi.py?
I can not finde it in
/config/custom_components/alexa_media/
/usr/local/lib/python3.12/site-packages/alexapy/ (no folder like that)
Is it because I am running HA with HAOS?

@danielbrunt57
Copy link
Collaborator

danielbrunt57 commented Dec 10, 2024

Where can I find the alexaapi.py? I can not finde it in /config/custom_components/alexa_media/ /usr/local/lib/python3.12/site-packages/alexapy/ (no folder like that) Is it because I am running HA with HAOS?

First, extract the new file to /config so you have access to it. Then in ssh/terminal session, run sudo docker exec -it homeassistant bash which gets you into the parent docker container for homeassistant. Now you can cd /usr/local/lib/python3.13/site-packages/alexapy and cp /config/alexaapi.py . When done, exit gets you back to the original terminal/ssh environment.

@Pingfragger
Copy link
Author

Where can I find the alexaapi.py? I can not finde it in /config/custom_components/alexa_media/ /usr/local/lib/python3.12/site-packages/alexapy/ (no folder like that) Is it because I am running HA with HAOS?

First, extract the new file to /config so you have access to it. Then in ssh/terminal session, run sudo docker exec -it homeassistant bash which gets you into the parent docker container for homeassistant. Now you can cd /usr/local/lib/python3.13/site-packages/alexapy and cp /config/alexaapi.py . When done, exit gets you back to the original terminal/ssh environment.

I tried to ssh into the parent docker container using the commands, but I can't:

[core-ssh ~]$ sudo docker exec -it homeassistant bash
-bash: sudo: command not found
[core-ssh ~]$ docker exec -it homeassistant bash
-bash: docker: command not found

In the file editor I can access the path /usr/local/lib but there are no further folders there.

Do you know why?

@danielbrunt57
Copy link
Collaborator

In the file editor I can access the path /usr/local/lib but there are no further folders there.

Do you know why?

Because you are only seeing a subset of the entire homeassistant raw container.

@danielbrunt57
Copy link
Collaborator

Are you running this Add-on:with protection disabled?

image

image

@Pingfragger
Copy link
Author

Pingfragger commented Dec 12, 2024

Thanks for the clarification, I am relatively new to HA.
I tried again after replacing alexaapi.py and __init__ with your files. I also tried the original __init__ but the result was the same. I restarted HA and made sure to wait long enough before logging in to amazon.de again.
I still get the 429:Too Many Requests error.
Is it possible that there is a problem with the account because the other account (with fewer devices) is working?
I can log in to my main account and control the devices with the Alexa app, but I get an error when I try to delete, rename or disable the connected devices in the Alexa app (e.g. Xiaomi sensors). I don't know if this is related to this issue.
Log:
home-assistant_alexa_media_2024-12-12T09-54-55.351Z.log

@danielbrunt57
Copy link
Collaborator

Here's my newest version of alexaapi.py with throttling and different Amazon region settings: alexaapi.zip

@Pingfragger
Copy link
Author

Here is my log. It looks different, but unfortunately it still does not work. Account created but no devices added
home-assistant_alexa_media_2024-12-12T17-37-59.913Z.log

@danielbrunt57
Copy link
Collaborator

The version I sent you wasn't correct as the API calls are too frequent.

024-12-12 18:29:51.357 DEBUG (MainThread) [alexapy.alexaapi] d********7@g*******m: Using Semaphores(2)
2024-12-12 18:29:51.357 DEBUG (MainThread) [alexapy.alexaapi] d********7@g*******m: Using asyncio.sleep(0.8)
2024-12-12 18:29:51.357 DEBUG (MainThread) [alexapy.alexaapi] [email protected]: Starting get_network_details
2024-12-12 18:29:51.626 DEBUG (MainThread) [alexapy.alexahttp2] Received raw message: --------abcde123

2024-12-12 18:29:51.727 DEBUG (MainThread) [alexapy.alexahttp2] Received response: 204:
2024-12-12 18:29:52.452 DEBUG (MainThread) [alexapy.alexaapi] d********7@g*******m: static GET: https://alexa.amazon.de/api/devices-v2/device returned 200:OK:application/json
2024-12-12 18:29:52.452 DEBUG (MainThread) [alexapy.alexaapi] api_calls: 1
2024-12-12 18:29:52.804 DEBUG (MainThread) [alexapy.alexaapi] d********7@g*******m: static GET: https://alexa.amazon.de/api/bluetooth?cached=false returned 200:OK:application/json
2024-12-12 18:29:52.805 DEBUG (MainThread) [alexapy.alexaapi] api_calls: 2
2024-12-12 18:29:53.763 DEBUG (MainThread) [alexapy.alexaapi] d********7@g*******m: static GET: https://alexa.amazon.de/api/device-preferences returned 200:OK:application/json
2024-12-12 18:29:53.763 DEBUG (MainThread) [alexapy.alexaapi] api_calls: 3
2024-12-12 18:29:53.781 DEBUG (MainThread) [alexapy.alexaapi] d********7@g*******m: static GET: https://alexa.amazon.de/api/dnd/device-status-list returned 200:OK:application/json
2024-12-12 18:29:53.781 DEBUG (MainThread) [alexapy.alexaapi] api_calls: 4
2024-12-12 18:29:54.675 DEBUG (MainThread) [alexapy.alexaapi] d********7@g*******m: static GET: https://alexa.amazon.de/api/phoenix returned 429:Too Many Requests:application/json
2024-12-12 18:29:54.675 DEBUG (MainThread) [alexapy.alexaapi] api_calls: 5
2024-12-12 18:29:54.676 INFO (MainThread) [alexapy.alexaapi] Backing off _static_request(...) for 5.0s (alexapy.errors.AlexapyTooManyRequestsError: Too Many Requests)
2024-12-12 18:29:54.717 DEBUG (MainThread) [alexapy.alexaapi] d********7@g*******m: static GET: https://alexa.amazon.de/api/bootstrap returned 200:OK:application/json
2024-12-12 18:29:54.718 DEBUG (MainThread) [alexapy.alexaapi] api_calls: 6
2024-12-12 18:30:00.564 DEBUG (MainThread) [alexapy.alexaapi] d********7@g*******m: static GET: https://alexa.amazon.de/api/phoenix returned 429:Too Many Requests:application/json
2024-12-12 18:30:00.565 DEBUG (MainThread) [alexapy.alexaapi] api_calls: 7
2024-12-12 18:30:00.566 INFO (MainThread) [alexapy.alexaapi] Backing off _static_request(...) for 6.0s (alexapy.errors.AlexapyTooManyRequestsError: Too Many Requests)
2024-12-12 18:30:07.465 DEBUG (MainThread) [alexapy.alexaapi] d********7@g*******m: static GET: https://alexa.amazon.de/api/phoenix returned 429:Too Many Requests:application/json
2024-12-12 18:30:07.466 DEBUG (MainThread) [alexapy.alexaapi] api_calls: 8
2024-12-12 18:30:07.466 INFO (MainThread) [alexapy.alexaapi] Backing off _static_request(...) for 12.0s (alexapy.errors.AlexapyTooManyRequestsError: Too Many Requests)
2024-12-12 18:30:20.369 DEBUG (MainThread) [alexapy.alexaapi] d********7@g*******m: static GET: https://alexa.amazon.de/api/phoenix returned 429:Too Many Requests:application/json
2024-12-12 18:30:20.370 DEBUG (MainThread) [alexapy.alexaapi] api_calls: 9
2024-12-12 18:30:20.370 INFO (MainThread) [alexapy.alexaapi] Backing off _static_request(...) for 24.0s (alexapy.errors.AlexapyTooManyRequestsError: Too Many Requests)

I've spent the last several hours debugging a new version and I just now heard alexa speak "home assistant has started" so I'm making progress! I have the semaphore lock based on region working but the tracking for AlexaAPI._last_request_time is not quite right yet as it keeps initializing back to zero when it should only initialize to 0 when alexapy/alexaapi first loads.

ChatGPT is a great help but it does make mistakes! It is nice enough though to thank me for pointing out the error or oversight it made! I just have to wait now for my daily free session to reset so I can continue with it...

@danielbrunt57
Copy link
Collaborator

2024-12-12 09:56:25.720 DEBUG (MainThread) [alexapy.alexaapi] Determined region 'na' for URL 'amazon.ca'
2024-12-12 09:56:25.720 DEBUG (MainThread) [alexapy.alexaapi] Determined region 'na' for URL 'amazon.ca'
2024-12-12 09:56:25.720 DEBUG (MainThread) [alexapy.alexaapi] Semaphore map: {'na': <asyncio.locks.Semaphore object at 0xffff2d82b850 [unlocked, value:4]>}
2024-12-12 09:56:25.720 DEBUG (MainThread) [alexapy.alexaapi] Region delays: {'eu': 0.7, 'fe': 0.5, 'na': 0.3}
2024-12-12 09:56:25.845 DEBUG (MainThread) [alexapy.alexaapi] d****l@b******a: POST: https://alexa.amazon.ca/api/behaviors/preview returned 200:OK:application/octet-stream
2024-12-12 09:56:25.845 DEBUG (MainThread) [alexapy.alexaapi] api_calls: 33
2024-12-12 09:56:27.144 DEBUG (MainThread) [alexapy.alexaapi] Determined region 'na' for URL 'https://www.amazon.ca/alexa-privacy/apd/rvh/customer-history-records'
2024-12-12 09:56:27.144 DEBUG (MainThread) [alexapy.alexaapi] Using region 'na' for URL 'https://www.amazon.ca/alexa-privacy/apd/rvh/customer-history-records'
2024-12-12 09:56:27.145 DEBUG (MainThread) [alexapy.alexaapi] Determined region 'na' for URL 'amazon.ca'
2024-12-12 09:56:27.145 DEBUG (MainThread) [alexapy.alexaapi] Semaphore map: {'na': <asyncio.locks.Semaphore object at 0xffff2d82b850 [unlocked, value:4]>}
2024-12-12 09:56:27.145 DEBUG (MainThread) [alexapy.alexaapi] Region delays: {'eu': 0.7, 'fe': 0.5, 'na': 0.3}
2024-12-12 09:56:27.145 DEBUG (MainThread) [alexapy.alexaapi] Region 'na' semaphore: <asyncio.locks.Semaphore object at 0xffff2d82b850 [unlocked, value:4]>
2024-12-12 09:56:27.145 DEBUG (MainThread) [alexapy.alexaapi] Delay: 0.3
2024-12-12 09:56:27.145 DEBUG (MainThread) [alexapy.alexaapi] async with semaphore
2024-12-12 09:56:27.146 DEBUG (MainThread) [alexapy.alexaapi] now: 1734026187.146064, region: na
2024-12-12 09:56:27.146 DEBUG (MainThread) [alexapy.alexaapi] last_request_time: {'na': 0}
2024-12-12 09:56:27.146 DEBUG (MainThread) [alexapy.alexaapi] Elapsed: 1734026187.146064
2024-12-12 09:56:27.146 DEBUG (MainThread) [alexapy.alexaapi] 
2024-12-12 09:56:27.268 DEBUG (MainThread) [alexapy.alexaapi] d****l@b******a: static GET: https://www.amazon.ca/alexa-privacy/apd/rvh/customer-history-records?startTime=1733939753985&endTime=1734112553985&recordType=VOICE_HISTORY&maxRecordSize=10 returned 429:Too Many Requests:text/html
2024-12-12 09:56:27.268 DEBUG (MainThread) [alexapy.alexaapi] api_calls: 34
2024-12-12 09:56:27.269 INFO (MainThread) [alexapy.alexaapi] Backing off _static_request(...) for 24.0s (alexapy.errors.AlexapyTooManyRequestsError: Too Many Requests)
2024-12-12 09:56:51.270 DEBUG (MainThread) [alexapy.alexaapi] Determined region 'na' for URL 'https://www.amazon.ca/alexa-privacy/apd/rvh/customer-history-records'
2024-12-12 09:56:51.270 DEBUG (MainThread) [alexapy.alexaapi] Using region 'na' for URL 'https://www.amazon.ca/alexa-privacy/apd/rvh/customer-history-records'
2024-12-12 09:56:51.270 DEBUG (MainThread) [alexapy.alexaapi] Determined region 'na' for URL 'amazon.ca'
2024-12-12 09:56:51.271 DEBUG (MainThread) [alexapy.alexaapi] Semaphore map: {'na': <asyncio.locks.Semaphore object at 0xffff2d82b850 [unlocked, value:4]>}
2024-12-12 09:56:51.271 DEBUG (MainThread) [alexapy.alexaapi] Region delays: {'eu': 0.7, 'fe': 0.5, 'na': 0.3}
2024-12-12 09:56:51.271 DEBUG (MainThread) [alexapy.alexaapi] Region 'na' semaphore: <asyncio.locks.Semaphore object at 0xffff2d82b850 [unlocked, value:4]>
2024-12-12 09:56:51.271 DEBUG (MainThread) [alexapy.alexaapi] Delay: 0.3
2024-12-12 09:56:51.271 DEBUG (MainThread) [alexapy.alexaapi] async with semaphore
2024-12-12 09:56:51.271 DEBUG (MainThread) [alexapy.alexaapi] now: 1734026211.271386, region: na
2024-12-12 09:56:51.271 DEBUG (MainThread) [alexapy.alexaapi] last_request_time: {'na': 0}
2024-12-12 09:56:51.271 DEBUG (MainThread) [alexapy.alexaapi] Elapsed: 1734026211.271386

@danielbrunt57
Copy link
Collaborator

danielbrunt57 commented Dec 13, 2024

I think I've finished it!
I had to adjust the 'na' region delay from '0.3' to '0.5'. At first I tried '1.0' and it was fine. Then I tried '0.5' and it also seems fine after several restarts but only time will tell. Currently, the map is set to {'eu': 0.7, 'fe': 0.5, 'na': 0.5} and I'm not seeing any
static GET: https://www.amazon.ca/alexa-privacy/apd/rvh/customer-history-records?startTime=1733939753985&endTime=1734112553985&recordType=VOICE_HISTORY&maxRecordSize=10 returned 429:Too Many Requests:text/html entries. The settings for eu and fe are just a guess at this point and will take some trial and error by others to adjust them.

_region_delay ensures a minimum delay since the last request by calling asyncio.sleep(delay - elapsed).
_region_limits = {"eu": 2, "fe": 3, "na": 4} is for the number of semaphores allowed and determines how may parallel requests are permitted at any given point in time. If all semaphores are in use, new requests are queued until an existing semaphore is released.

alexaapi.zip

@danielbrunt57
Copy link
Collaborator

You can use this automation to create a persistent notification when alexaapi triggers a 429: Too Many Requests error...

alias: "System Log Event: alexapy.alexaapi"
description: ""
mode: single
triggers:
  - event_type: system_log_event
    event_data:
      name: alexapy.alexaapi
    trigger: event
conditions:
  - condition: template
    value_template: "{{ \"Too Many Requests\" in trigger.event.data.message[0] }}"
    enabled: true
actions:
  - action: persistent_notification.create
    data:
      title: alexapy.alexaapi
      message: "{{ trigger.event.data.message[0] }}"

@Pingfragger
Copy link
Author

I tried the new file and now it doesn't take 30 seconds to load after login, just a few seconds, but unfortunately there are still devices showing up.
Also, the rule did not trigger and I no longer see the too many requests error.
Log: home-assistant_alexa_media_2024-12-13T11-45-28.245Z.log

@danielbrunt57
Copy link
Collaborator

My apolgies! I forgot that I added this to alexalogin.py so I could use AMP's Advanced debugging option to control additional logging output in alexaapi.py or not:

    @property
    def debug(self):
        return self._debug

AlexaLogin had a few advanced debug statements but only defined debug internally as self._debug.
The above code makes login.debug available elsewhere. AlexaAPI never did have advanced debugging (until now).

Replace your file with: alexalogin.zip

@Pingfragger
Copy link
Author

Pingfragger commented Dec 13, 2024

No worries!
Now it loaded longer, but no devices.
Log: home-assistant_alexa_media_2024-12-13T14-32-49.143Z.log

@danielbrunt57
Copy link
Collaborator

danielbrunt57 commented Dec 13, 2024

2024-12-13 15:32:10.694 DEBUG (MainThread) [alexapy.alexaapi] Last request time: 1734100330.691732, Elapsed: 0.003165006637573242
2024-12-13 15:32:10.695 DEBUG (MainThread) [alexapy.alexaapi] Throttling: sleeping for 0.6968349933624267 seconds
2024-12-13 15:32:10.881 DEBUG (MainThread) [alexapy.alexaapi] Updated the last request time for the region: 1734100330.8810558
2024-12-13 15:32:10.882 DEBUG (MainThread) [alexapy.alexaapi] d********7@g*******m: static GET: https://alexa.amazon.de/api/dnd/device-status-list returned 200:OK:application/json
2024-12-13 15:32:10.882 DEBUG (MainThread) [alexapy.alexaapi] api_calls: 4
2024-12-13 15:32:10.883 DEBUG (MainThread) [alexapy.alexaapi] Last request time: 1734100330.8810558, Elapsed: 0.0019960403442382812
2024-12-13 15:32:10.883 DEBUG (MainThread) [alexapy.alexaapi] Throttling: sleeping for 0.6980039596557617 seconds
2024-12-13 15:32:11.523 DEBUG (MainThread) [alexapy.alexaapi] Updated the last request time for the region: 1734100331.523008
2024-12-13 15:32:11.524 DEBUG (MainThread) [alexapy.alexaapi] d********7@g*******m: static GET: https://alexa.amazon.de/api/bootstrap returned 200:OK:application/json
2024-12-13 15:32:11.524 DEBUG (MainThread) [alexapy.alexaapi] api_calls: 5
2024-12-13 15:32:11.766 DEBUG (MainThread) [alexapy.alexaapi] Updated the last request time for the region: 1734100331.7662325
2024-12-13 15:32:11.767 DEBUG (MainThread) [alexapy.alexaapi] d********7@g*******m: static GET: https://alexa.amazon.de/api/phoenix returned 429:Too Many Requests:application/json
2024-12-13 15:32:11.767 DEBUG (MainThread) [alexapy.alexaapi] api_calls: 6
2024-12-13 15:32:11.768 INFO (MainThread) [alexapy.alexaapi] Backing off _static_request(...) for 10.0s (alexapy.errors.AlexapyTooManyRequestsError: Too Many Requests)
2024-12-13 15:32:21.770 DEBUG (MainThread) [alexapy.alexaapi] Using region 'eu' for URL 'https://alexa.amazon.de/api/phoenix'
2024-12-13 15:32:21.770 DEBUG (MainThread) [alexapy.alexaapi] Region: eu, semaphore: <asyncio.locks.Semaphore object at 0x7f803ebc50 [unlocked, value:2]>, delay: 0.7
2024-12-13 15:32:21.771 DEBUG (MainThread) [alexapy.alexaapi] Region 'eu' semaphore: <asyncio.locks.Semaphore object at 0x7f803ebc50 [unlocked, value:2]>, delay: 0.7
2024-12-13 15:32:21.771 DEBUG (MainThread) [alexapy.alexaapi] Last request time: 1734100331.7662325, Elapsed: 10.005157470703125
2024-12-13 15:32:21.857 DEBUG (MainThread) [alexapy.alexaapi] Updated the last request time for the region: 1734100341.8575726
2024-12-13 15:32:21.858 DEBUG (MainThread) [alexapy.alexaapi] d********7@g*******m: static GET: https://alexa.amazon.de/api/phoenix returned 429:Too Many Requests:application/json
2024-12-13 15:32:21.858 DEBUG (MainThread) [alexapy.alexaapi] api_calls: 7
2024-12-13 15:32:21.859 INFO (MainThread) [alexapy.alexaapi] Backing off _static_request(...) for 10.0s (alexapy.errors.AlexapyTooManyRequestsError: Too Many Requests)
2024-12-13 15:32:31.860 DEBUG (MainThread) [alexapy.alexaapi] Using region 'eu' for URL 'https://alexa.amazon.de/api/phoenix'
2024-12-13 15:32:31.860 DEBUG (MainThread) [alexapy.alexaapi] Region: eu, semaphore: <asyncio.locks.Semaphore object at 0x7f803ebc50 [unlocked, value:2]>, delay: 0.7
2024-12-13 15:32:31.860 DEBUG (MainThread) [alexapy.alexaapi] Region 'eu' semaphore: <asyncio.locks.Semaphore object at 0x7f803ebc50 [unlocked, value:2]>, delay: 0.7
2024-12-13 15:32:31.861 DEBUG (MainThread) [alexapy.alexaapi] Last request time: 1734100341.8575726, Elapsed: 10.00345230102539
2024-12-13 15:32:31.931 DEBUG (MainThread) [alexapy.alexaapi] Updated the last request time for the region: 1734100351.931332
2024-12-13 15:32:31.932 DEBUG (MainThread) [alexapy.alexaapi] d********7@g*******m: static GET: https://alexa.amazon.de/api/phoenix returned 429:Too Many Requests:application/json
2024-12-13 15:32:31.932 DEBUG (MainThread) [alexapy.alexaapi] api_calls: 8
2024-12-13 15:32:31.933 INFO (MainThread) [alexapy.alexaapi] Backing off _static_request(...) for 12.0s (alexapy.errors.AlexapyTooManyRequestsError: Too Many Requests)
2024-12-13 15:32:39.277 WARNING (MainThread) [alexapy.helpers] alexaapi.get_network_details((<alexapy.alexalogin.AlexaLogin object at 0x7f93587b10>,), {}): Timeout error occurred accessing AlexaAPI: An exception of type CancelledError occurred. Arguments:
()
2024-12-13 15:32:39.278 ERROR (MainThread) [custom_components.alexa_media] Error fetching alexa_media data: Error communicating with API: 
2024-12-13 15:32:39.278 DEBUG (MainThread) [custom_components.alexa_media] Finished fetching alexa_media data in 30.002 seconds (success: False)

Can you edit alexaapi.py and change region_limits and region_delays to:
_region_limits = {"eu": 1, "fe": 2, "na": 2} (one semaphore)
_region_delays = {"eu": 2.0, "fe": 0.5, "na": 0.7} (minimum two seconds between requests)

This will slow things down considerably but I am just attempting to achieve
a successful GET: https://alexa.amazon.de/api/phoenix...

@Pingfragger
Copy link
Author

Sure. I changed that and here is the Log:
home-assistant_alexa_media_2024-12-13T17-11-30.320Z.log

@danielbrunt57
Copy link
Collaborator

Since extended delays did not work, change alexaapi region settings to:

_region_limits = {"eu": 2, "fe": 3, "na": 4}
_region_delays = {"eu": 0.7, "fe": 0.6, "na": 0.5}

Let's try and avoid the get_network_details API call.
In alexa_media/__init__.py line 333 change should_get_network to False

            "second_account_index": 0,
            "should_get_network": False,
            "options": {

You might also want to disable the system option Enable newly added entities:

image

@Pingfragger
Copy link
Author

Amazing! It worked! All devices are found with no errors. Thank you so much! Do I still have to disable Enable newly added entities?
What is the problem with that?

Do you have any idea why it previously worked with the second account but not with my main account?
The biggest difference was that my main account had a lot of secondary devices like Xiaomi sensors.

The log of the working main account login:
home-assistant_alexa_media_2024-12-14T18-28-21.788Z.log

@danielbrunt57
Copy link
Collaborator

danielbrunt57 commented Dec 17, 2024

Since I'm not quite sure which setting is actually triggering the "429: Too Many Requests", you could try restoring "should_get_network": False, back to "should_get_network": True, but leave Enable newly added entities disabled to see if that change alone woks for your main account or not. If that fails then reverse the two settings and try again.
Alternatively, you can try enabling Enable newly added entities restart HA and see if it works.

@Pingfragger
Copy link
Author

Pingfragger commented Dec 18, 2024

I tested the following:
"should_get_network": True and Enable newly added entities disabled = 429:Too many requests error again (see log)
should_get_network: False and Enable newly added entities enabled = worked again
home-assistant_alexa_media_2024-12-18T09-28-56.706Z.log

Does should_get_network have a problem with too many devices in the account or corrupt devices in the account? All secondary devices like Xiaomi sensors are not editable or deleteable in the Amazon app (Error when I try).

@danielbrunt57
Copy link
Collaborator

Does should_get_network have a problem with too many devices in the account or corrupt devices in the account? All secondary devices like Xiaomi sensors are not editable or deletable in the Amazon app (Error when I try).

I'm working on a feature change for include_devices & exclude_devices which itself is unrelated to your issue but it has caused me to delve further inside AMP to gain a better understanding of should_get_network.
should_get_network causes get_network_details to retrieve via the api/phoenix "GET", everything about the "alexa" network.

This is the detailed response for my Alexa network: get_network_details response.txt

As to whether too many devices or corruption is causing your error, I have no idea as that is handled by the undocumented Amazon API we're using. If it's simply too many devices, I would expect a 413 Payload Too Large response. If it's internal failure due to corruption, I'd expect the API to return 500 Internal Server Error - A generic error message, given when an unexpected condition was encountered and no more specific message is suitable instead of the current 429 Too Many Requests (RFC 6585)- The user has sent too many requests in a given amount of time. Intended for use with rate-limiting schemes.

Reference: List of HTTP status codes

You may need to contact Amazon to address the corruption in your account or, delete the account and set it up from scratch again. Given my past experience trying to get support from Amazon, I'm not sure which approach is going to be the easier of the two! The trick with Amazon is being able to get past their Tier 1 support who quite often fail to understand the issue & try to pass it off with a generic answer.

@danielbrunt57 danielbrunt57 changed the title No devices are found (amazon.de): api/phoenix repeatedly returns 429:Too Many Requests resulting in CancelledError thus failure to get network details NO DEVICES FOUND (amazon.de): api/phoenix repeatedly returns 429:Too Many Requests resulting in CancelledError & failure to get network details Dec 18, 2024
@danielbrunt57 danielbrunt57 pinned this issue Dec 18, 2024
@danielbrunt57 danielbrunt57 changed the title NO DEVICES FOUND (amazon.de): api/phoenix repeatedly returns 429:Too Many Requests resulting in CancelledError & failure to get network details NO DEVICES FOUND: api/phoenix repeatedly returns 429:Too Many Requests resulting in CancelledError & failure to get network details Dec 18, 2024
@Pingfragger
Copy link
Author

Pingfragger commented Dec 18, 2024

Thank you for your work!
If you need me to test anything, let me know.
Thanks for the explanation and helping me understand the API answers better.
I have contacted amazon several times but after going through tier 1 support and opening a ticket to the technical team nothing has happened. An amazon employee told me that there is a problem with the app that more people are having. I will continue to look for a solution or move to a new amazon with the echo devices account for HA only.

OT: Has Amazon reduced the possible features of the integration?
1-2 months ago, when I was using OpenHab, I had a lot of features that I don't have with the Alexa Media Player, like TTS volume in addition to normal volume, or giving an echo a text command and the echo acts like it's an audio command.

@danielbrunt57
Copy link
Collaborator

danielbrunt57 commented Dec 19, 2024

OT: Has Amazon reduced the possible features of the integration?

That I don't know.

1-2 months ago, when I was using OpenHab, I had a lot of features that I don't have with the Alexa Media Player, like TTS volume in addition to normal volume, or giving an echo a text command and the echo acts like it's an audio command.

From the little bit of looking I did into OpenHAB (Java) a few months back, my takeaway is that it has more work being done on it than AMP and has continued to evolve and change, as has Apollon77/alexa-remote (JavaScript). Alexa Media Player (Python) not so much. They all have to emulate the Alexa app and the header information in AMP for that emulated app hasn't changed in years. alexapy has some info in const.py for that:

"""Python Package for controlling Alexa devices (echo dot, etc) programmatically.

SPDX-License-Identifier: Apache-2.0

Constants.

For more details about this api, please refer to the documentation at
https://gitlab.com/keatontaylor/alexapy
"""

EXCEPTION_TEMPLATE = "An exception of type {0} occurred. Arguments:\n{1!r}"

CALL_VERSION = "2.2.556530.0"
APP_NAME = "Alexa Media Player"
USER_AGENT = f"AmazonWebView/Amazon Alexa/{CALL_VERSION}/iOS/16.6/iPhone"

but there are HTTP headers scattered throughout the code and I'm wondering if all that old Alexa app versioning is affecting how Amazon responds.

I can look up that info from Apollon77/alexa-remote and you can try changing it in const.py...

@danielbrunt57
Copy link
Collaborator

My installation still works after editing alexapy/const.py with:

"""Python Package for controlling Alexa devices (echo dot, etc) programmatically.

SPDX-License-Identifier: Apache-2.0

Constants.

For more details about this api, please refer to the documentation at
https://gitlab.com/keatontaylor/alexapy
"""

EXCEPTION_TEMPLATE = "An exception of type {0} occurred. Arguments:\n{1!r}"

# Apollon77/alexa-remote - alexa-remote.js:
# const officialUserAgent = 'AppleWebKit PitanguiBridge/2.2.595606.0-[HARDWARE=iPhone14_7][SOFTWARE=17.4.1][DEVICE=iPhone]';

# CALL_VERSION = "2.2.556530.0"
CALL_VERSION = "2.2.595606.0"
APP_NAME = "Alexa Media Player"
# USER_AGENT = f"AmazonWebView/Amazon Alexa/{CALL_VERSION}/iOS/16.6/iPhone"
# USER_AGENT = f"AmazonWebView/Amazon Alexa/{CALL_VERSION}/iOS/17.4.1/iPhone"
# Trying...
USER_AGENT = f"AppleWebKit PitanguiBridge/2.2.595606.0-[HARDWARE=iPhone14_7][SOFTWARE=17.4.1][DEVICE=iPhone]"

@Pingfragger
Copy link
Author

Is it possible to update AMP without undoing the changes I made?
Is should_get_network: False the only relevant change made to make it work?
Will the changes be implemented in a future release or was it just a problem with my system?

Thank you!

@danielbrunt57
Copy link
Collaborator

Is it possible to update AMP without undoing the changes I made?

No.

Is should_get_network: False the only relevant change made to make it work?

I believe so. The other changes had no effect on your solving your error. It wasn't until we disabled should_get_network that you were able to get AMP to work for you with your original account

Will the changes be implemented in a future release or was it just a problem with my system?

I inquired in other posted issues re: no devices found if they had the 429 error but so far no responses either way. As it stands now, I'm thinking it may just be a problem in your original Amazon account and not an issue in general that needs fixing in AMP.

@Pingfragger
Copy link
Author

Pingfragger commented Dec 22, 2024

Thanks for your work!
I will try to update AMP and set should_get_network to False again.

What are the impacts and which functionalities, entities, or attributes are unavailable or not updated when should_get_network is set to False and is last_called affected by that setting?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
amazonissue Issue needs to have a change made by Amazon
Projects
None yet
Development

No branches or pull requests

3 participants