alexa_media_player: Alexa API / Too many requests

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

I am getting quite a lot of errors saying that there were too many requests and other problems (getting history records). The problem seems to be the Indoor Air Quallity Monitor, at least it is the only Amazon device I use except my Echos. I am using it as temperature and hygrometer device, I think the device is sending updates every 5 minutes.

To Reproduce

  1. Go to ‘…’
  2. Click on ‘…’
  3. Scroll down to ‘…’
  4. See error

Expected behavior

No problem with getting data, not getting the "too many requests error.

Screenshots

image

System details

  • Home-assistant (version): 2024.1.5 // 2023.12.1
  • alexa_media (version from const.py or HA startup): 4.9.0
  • alexapy (version from pip show alexapy or HA startup): Package not found
  • Amazon 2FA is enabled (y/n). <!—We will not debug login issues if unanswered—>: yes

Logs Please provide logs. 1.) Dieser Fehler wurde von einer benutzerdefinierten Integration verursacht

Logger: custom_components.alexa_media Source: helpers/update_coordinator.py:332 Integration: Alexa Media Player (documentation, issues) First occurred: 18:12:58 (1 occurrences) Last logged: 18:12:58

Error fetching alexa_media data: Error communicating with API:

2,) Dieser Fehler wurde von einer benutzerdefinierten Integration verursacht

Logger: alexapy.helpers Source: custom_components/alexa_media/init.py:756 Integration: Alexa Media Player (documentation, issues) First occurred: 18:12:58 (2 occurrences) Last logged: 18:12:58

alexaapi.get_customer_history_records((<alexapy.alexalogin.AlexaLogin object at 0x7f74fc4950>,), {‘max_record_size’: 10}): An error occurred accessing AlexaAPI: An exception of type AlexapyTooManyRequestsError occurred. Arguments: (‘’,) alexaapi.get_last_device_serial((<alexapy.alexalogin.AlexaLogin object at 0x7f74fc4950>,), {}): An error occurred accessing AlexaAPI: An exception of type AlexapyTooManyRequestsError occurred. Arguments: (‘’,)

3.) Dieser Fehler wurde von einer benutzerdefinierten Integration verursacht

Logger: alexapy.alexaapi Source: custom_components/alexa_media/init.py:756 Integration: Alexa Media Player (documentation, issues) First occurred: 18:12:58 (1 occurrences) Last logged: 18:12:58

Giving up _static_request(…) after 5 tries (alexapy.errors.AlexapyTooManyRequestsError)

Additional context

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 32
  • Comments: 151 (2 by maintainers)

Most upvoted comments

Okay, can we please stop writing me too? Getting an email notification just because someone can’t press thumbs up and instead has to write “same problem” isn’t helping. Thanks.

In case it wasn’t obvious, this is an Amazon issue and there’s nothing we can do about it here. I’ll leave this open for reference.

ok. I understand it’s a problem with Amazon’s servers. But I ask you, is there any solution to limit the frequency of the problem? In other words… Does the problem depend on the number of requests made on single session (so the more devices you have, the more the problem occurs) or on the frequency with which each account connects to the servers to check the status of the devices? Is there a chance that the situation can be resolved somehow or will we have to learn to live with this aspect?

Same problem too

So, in the last 2 weeks & my many (MANY) hours of doing this, that, and the other inside alexa_media, I’ve come to the realization that the too many requests error seems to have nothing to do with voice history or the record size in alexapy. It seems to simply be too many frequent requests to the API. I’ve been triggering it a lot recently while coding my numerous ideas to somehow get last_alexa updated in a timely fashion. With the architecture of alexa_media/alexapy and the limitations imposed by Amazon, plus their recent removal of the PUSH_ACTIVITY command via the http2 connection, I think it’s best that the integration’s internal automatic updates of last_alexa be removed while leaving the service call alexa_media.update_last_called for us to use when we’ve programmatically determined that we are about to use notify.alexa_media_last_called. I’ve not yet given up completely on my last approach , but I think I’m very close to throwing in the towel…

Would be nice if there was a away to adjust this setting without having to go through uninstalling/reinstalling.

@alandtse I have made progress on rewriting the integration to support this. I’ve forked the repo but still need to to more testing before submitting a PR as I haven’t run though initial setup yet. It took me two solid days to refactor config_flow.py and related files. Lots of head scratching, editing and restart after restart after restart…

image

This is an issue with Amazon’s rate limit throttling which we have no control over other than to abide and back off our requests. I know that doesn’t help but I offer this automation which will alert you to a problem via a persistent notification so you can at least be more aware of the error when it has occured… (two items are disabled - your choice as to whether to enable them or not!)

alias: "System Log Event: alexapy.alexaapi"
description: ""
trigger:
  - platform: event
    event_type: system_log_event
    event_data:
      name: alexapy.alexaapi
condition:
  - condition: template
    value_template: "{{ \"Too Many Requests\" in trigger.event.data.message[0] }}"
    enabled: false
action:
  - action: persistent_notification.create
    data:
      title: alexapy.alexaapi
      message: "{{ trigger.event.data.message[0] }}"
  - action: homeassistant.reload_config_entry
    data: {}
    enabled: false
    target:
      entity_id: media_player.echo
mode: single

Came here to say I just set this up yesterday for the first time and I’m seeing the exact same issue. I only have the one AQM on my account and no other devices.

I don’t think this happens only to a few users. It’s just not everybody commenting on this issue.

I think that people with a lot of echo devices only might have these issues. If you just have a single speaker, the integration might not send as many requests than with 10+ devices.

also other smarthome tools like FHEM have problems - Amazon changed something

I appreciate the effort you’ve put in and I can support your idea of the reduced calls for the last_update, it seems unnecessary to use the API when most of the time that info isn’t needed. We can always call for an update when/if needed.

I’ve found it. It’s the “scan_inteval” in this entry in config/.storage/core.config_entries:

      {
        "data": {
          "otp_secret": "<2FA App Key>",
          "email": "your_email@domain",
          "password": " <password> ",
          "url": "amazon.com",
          "debug": false,
          "scan_interval": 1800,
          "include_devices": "",
          "exclude_devices": "",
          "oauth": {
            "access_token": <Access Token>
            "refresh_token": <Refresh Token>
            "expires_in": 1720217060.239656,
            "mac_dms": {
              "device_private_key": <Device Private Key>
              "adp_token": <ADP Token>
            },
            "code_verifier": <Code Verifier>,
            "authorization_code": <Authorization Code>
          }
        },

Having an issue here, too.

Having this problem too. Is there anything we can do to help this along and get it sorted? The integration is very unstable because of this issue and its becoming quite unreliable… Is there any way that the integration can be changed so we need our own amazon dev account or something like that?

For a few days everything seemed to be back to normal. but from this night the problems started again and the entities are no longer available intermittently. Let’s hope they solve it

You’ll have to ask Amazon. We already limit our connections. https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429 is what they’re telling us. Maybe there’s a PR to see if Amazon sends us actual retry info. Otherwise we already use exponential backoff with jitter which is an AWS recommended practice.

Same problem

Error fetching alexa_media data: Error communicating with API: Too Many Requests

After this error I a having a 5 minute gap in history data for my air quality monitor, in the dashboard it is shown as unavailable for the same time. My Echos are then not capable to execute HA scripts using tts.

sometimes the Echo are unavailable, the related service not available and repair required

Same problem

Same problem here from a couple of weeks ago, no HA configuration changed in the last month. The problem was already succeeded last year, I suppose this is a problem caused by limited resources available in the AWS cloud to the customer without regular subscription, but I could be wrong …

also other smarthome tools like FHEM have problems - Amazon changed something

Yes, I also think so. I integrated the air quality sensor in December and the errors started approx. 10 days (?) ago. I cannot be precise here as I noted them by coincidence when I saw my dashboard is not showing values for the sensors every now and then.

I’ve found it. It’s the “scan_inteval” in this entry in config/.storage/core.config_entries:

      {
        "data": {
          "otp_secret": "<2FA App Key>",
          "email": "your_email@domain",
          "password": " <password> ",
          "url": "amazon.com",
          "debug": false,
          "scan_interval": 1800,
          "include_devices": "",
          "exclude_devices": "",
          "oauth": {
            "access_token": <Access Token>
            "refresh_token": <Refresh Token>
            "expires_in": 1720217060.239656,
            "mac_dms": {
              "device_private_key": <Device Private Key>
              "adp_token": <ADP Token>
            },
            "code_verifier": <Code Verifier>,
            "authorization_code": <Authorization Code>
          }
        },

I waited two days to be sure, but this DID work for me. Thank you!

Can you clarify on where to set the polling rate, all I can see is the setting for the time to “merge” requests.

image

Can you clarify on where to set the polling rate, all I can see is the setting for the time to “merge” requests.

NO Problem Here / RESOLVED : only an error of the skill that was strangely unregistered

Same issue here since reboot and nothing help … stay off after reboot too evrything was working fine there is a few hours ago

2024-06-13 20:04:11.556 ERROR (MainThread) [alexapy.alexaapi] Giving up _static_request(...) after 5 tries (alexapy.errors.AlexapyTooManyRequestsError: Too Many Requests) 2024-06-13 20:04:11.556 WARNING (MainThread) [alexapy.helpers] alexaapi.get_customer_history_records((<alexapy.alexalogin.AlexaLogin object at 0x7f62928530>,), {'max_record_size': 10}): An error occurred accessing AlexaAPI: An exception of type AlexapyTooManyRequestsError occurred. Arguments: ('Too Many Requests',) 2024-06-13 20:04:11.557 WARNING (MainThread) [alexapy.helpers] alexaapi.get_last_device_serial((<alexapy.alexalogin.AlexaLogin object at 0x7f62928530>,), {}): An error occurred accessing AlexaAPI: An exception of type AlexapyTooManyRequestsError occurred. Arguments: ('Too Many Requests',) 2024-06-13 20:04:11.557 ERROR (MainThread) [custom_components.alexa_media] Error fetching alexa_media data: Error communicating with API: Too Many Requests

I’m pretty confident that it’s not a localised thing to individual configurations, but that there is too many people probably using the add on now globally and that’s what is causing it to hit a limit… of course, I can’t be sure either… But I do notice it happens more often around the same time of the day when it does happen. I tried probing through some of alandtse’s code to see if I could spot anything that might indicate my theory and any way I might be able to suggest an alternative or offer some help but it’s a pretty complex add on and I’m not a powerful python coder (yet) so I stopped when I realised it was way over my head…

Problem disappear now for me… nothing done… 😃

same issue here (5 devices)

Same issue for me too, i have 3 echo devices

Same issue for me too.

I have the same issue. Also I noticed that service to update last called alexa has disappeared. I have many alexa devices (10).

You’ll have to ask Amazon. We already limit our connections. https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429 is what they’re telling us. Maybe there’s a PR to see if Amazon sends us actual retry info. Otherwise we already use exponential backoff with jitter which is an AWS recommended practice.

Hi Alan but I wanted to ask why this behavior doesn’t seem to affect everyone? On my side, I haven’t changed anything and it started showing up about 3 weeks ago many others do not have this problem If it were Amazon, shouldn’t it be a widespread problem?

wbr 😃

Didn’t work for me either

I had the same problem. I deleted the following file: /homeassistant/.storage/alexa_media.myemailadress@domain.com.pickle

After the integration was reloaded, the error did not reappear. Let’s see how it goes now…

Hi 👋, same problem for me; I bring you my experience and the series of facts (coincidences?) that occurred at the same time as the errors appeared:

  1. I had just gotten the “add connected devices” option to get the temperature sensor of one of my 10 alexa devices. I deactivated and deleted this entity firstly because these error messages started and secondly because it was not very precise and timely in updating; I prefer to keep the other sensors I have integrated. after restoring everything to how it was before the 3 error messages continued to appear.
  2. I looked in core.config_entries for that value (object at 0x7f8879d8d690) reported in the 3 occurrences of the warning message relating to the “Logger: alexapy.helpers” and I discovered that it referred to the “radio browser” integration that I had disabled; at this point I re-enabled it but the errors continued; I decided to remove it completely but the result did not change.

maybe they are just coincidences but this is it and unfortunately even by removing what seemed to me to be the cause, the errors continue.

I am also seeing similar behaviour:

Error fetching alexa_media data: Error communicating with API: Too Many Requests 6:23:58 AM – (ERROR) Alexa Media Player (custom integration) - message first occurred at January 29, 2024 at 12:50:17 PM and shows up 7 times alexaapi.get_customer_history_records((<alexapy.alexalogin.AlexaLogin object at 0x7fc34466ca10>,), {'max_record_size': 10}): An error occurred accessing AlexaAPI: An exception of type AlexapyTooManyRequestsError occurred. Arguments: ('Too Many Requests',) 6:23:58 AM – (WARNING) Alexa Media Player (custom integration) - message first occurred at January 29, 2024 at 12:50:17 PM and shows up 16 times Giving up _static_request(...) after 5 tries (alexapy.errors.AlexapyTooManyRequestsError: Too Many Requests) 6:23:58 AM – (ERROR) Alexa Media Player (custom integration) - message first occurred at January 29, 2024 at 12:50:17 PM and shows up 7 times

Just as another datapoint,

AMP had been running just fine apart from my timers failing to update. So I thought I’d remove and re-add the integration.

Since then, although I can complete the 2FA login flow (with the ‘hack’ of choosing the option to create a new account, seeing the message that my email address already has an account, then switching back to login as an existing user – that gets past the webpage login loop).

But, no devices are detected and I see the ‘too many requests’ errors in the logs.

I don’t know why Amazon had no problem with the number of requests before I uninstalled and reinstalled the integration. But now they do.

I’ve left the integration uninstalled for two weeks before attempting to re-add it, but immediately I get ‘too many requests’. Perhaps the speed of the initial login actions are triggering it? If I get some time I’ll dig into AMP (or rather alexapy) and scatter some delays around the login code and see what happens.

(this is using amazon.co.uk)

edit:

My logs show that at least some calls succeed. And I note that alexapy does do some backing-off. But it doesn’t back-off by much: 0.7, 0.1 seconds, for instance.

image

Been fiddling with the ‘backoff’ option on alexapy’s API calls. No joy. Will try some more after work.

Please try v4.12.5 just released and advise your findings. Thanks.

Mine is error free and I am back to the default of 60 seconds. But then again, I don’t say much to Alexa except Good morning and Good night.

Have you tried saying “Alexa, I’m sorry, it’s all my fault and I’ll try not to upset you again” or “Alexa, I love you and only you!”?

Less than 3-10 seconds…

image

It would seem Voice History retention might have a major impact on AMP. See this step-by-step guide on how to change your settings.: How to Delete Alexa Recordings by Voice

I’ve found it. It’s the “scan_inteval” in this entry in config/.storage/core.config_entries:

      {
        "data": {
          "otp_secret": "<2FA App Key>",
          "email": "your_email@domain",
          "password": " <password> ",
          "url": "amazon.com",
          "debug": false,
          "scan_interval": 1800,
          "include_devices": "",
          "exclude_devices": "",
          "oauth": {
            "access_token": <Access Token>
            "refresh_token": <Refresh Token>
            "expires_in": 1720217060.239656,
            "mac_dms": {
              "device_private_key": <Device Private Key>
              "adp_token": <ADP Token>
            },
            "code_verifier": <Code Verifier>,
            "authorization_code": <Authorization Code>
          }
        },

I used a text editor to increase “scan_interval” from 60 to 3600. But, after restarting HA, the value reverted back to 60.

Can you clarify on where to set the polling rate, all I can see is the setting for the time to “merge” requests.

Appreciate the example image, but your configuration screen doesn’t look like anything like mine.

Going to Settings --> Devices & Integrations --> Alexa Media Player --> Configure

Gives me two options:

  • Seconds to wait to queue commands together
  • Public URL to access Home Assistant

So where do I find that configuration screen?

   - Benjamin

What about allowing us to set a throttling value? Or restricting the devices to be pushed into the Amazon cloud to help reduce the number of queries that we’re making?

AMP does not push anything to the cloud. All of your Alexa devices are connected to the cloud and have nothing to do with HA or AMP. AMP only polls Amazon every xx seconds which is set when you install it. I installed my integration with 3600 seconds to overcome the Too many requests error. The default 60 seconds triggered it. 600 seconds worked for a while but then started triggering it. So far, 3600 is fine. Then to compensate, I always call alexa_media.update_last_called and wait for it to complete before I use media_player.last_alexa in my scripts/automations.

What about allowing us to set a throttling value? Or restricting the devices to be pushed into the Amazon cloud to help reduce the number of queries that we’re making?

has anyone found a way to at least improve the situation even if just a bit?

I can tell you what I did yesterday:

-My Alexa was unavailable on my HA. -This is the last line in the error entry in the log about alexa: “An error occurred accessing AlexaAPI: An exception of type AlexapyTooManyRequestsError occurred. Arguments: (‘Too Many Requests’,)”

I unplug my alexa from power for about 30 seconds and reconnect. Let it do his thing, and get connected to it’s wifi with her final blue flashes.

Went to my HA UI, --> dev-tools --> Check config and Restart HA…

After restart, with my recently rebooted Alexa Echo this time… my alexa entities became available upon restart. Since yesterday, my alexa is working and giving me all the TextToSpeech messages I have configured on her.

Don’t now if it will last, but at least, I know when someone is knocking at the door for the last 24 hours. Hope it helps.

(note: I must add that I still see ‘tooManyRequests’ messages in the log. They are still there, but at least my Echo is available and working)

Same Problem for me My echo device were unavailable all the day since midnight this day… HA restart and Alexa Echo didn’t change anything… A lot error of too many request in my logs. The service is up from few minutes for now… I have no include device by Echo device checked

in my HA the errors don’t stop.

Just got this error for the first time yesterday (March 4th)

For a few days everything seemed to be back to normal. but from this night the problems started again and the entities are no longer available intermittently. Let’s hope they solve it

and now again also for me after some days without warning / errors 😦

I confirm that by commenting “API:” statement in the configuration.yaml file the messages have disappeared

Guys, It seems that I found a solution (temp solution?) Comment media_player and api in configuration.yaml as in the image below, restart HA and works again!

Screenshot_20240225_084056_Home Assistant

hello all, the error seems related to poll frequency of devices, if i disable “Enable polling for updates” under system option for the integration the error stop and logs are also clean. In this case as axpected the device status are not more in sync but TSS and device settings for devices work as expected. It seems related to the frequency for getting updates for the various device, furthermore i’ve noticed that the error is present in the log every 10 minutes with polling enabled, for now i’ve disabled the option but is not a solution. leaving all at default after some hours i need to re-authenticate and devices are most of time no reacheble. i don’t know if this can be helpful or not

Same here. I think most users are not aware of the issue. I wouldn’t have noticed it, if I wouldn’t have checked the dashboard in that moment when the temperature sensor of my air quality monitor was not available.

Error fetching alexa_media data: Error communicating with API: Too Many Requests

After this error I a having a 5 minute gap in history data for my air quality monitor, in the dashboard it is shown as unavailable for the same time.

My Echos are then not capable to execute HA scripts using tts.

same thing for me too