Skip to content

Handle RATE_LIMIT_HIT (Rate limit exceeded) errors #773

Description

@i-ky

It would be nice if this library handled RATE_LIMIT_HIT errors automatically by sleeping for retry-after seconds and retrying the request. Otherwise this logic needs to be implemented in every user application.

Activity

  1. i-ky commented on Jan 18, 2023

    @i-ky
    ContributorAuthor

    @zulipbot add "enhancement" "help wanted"

  2. Fahdmoh01 commented on Oct 1, 2023

    @Fahdmoh01

    @zulipbot claim

  3. zulipbot commented on Oct 1, 2023

    @zulipbot
    Member

    Welcome to Zulip, @Fahdmoh01! We just sent you an invite to collaborate on this repository at https://github.com/zulip/python-zulip-api/invitations. Please accept this invite in order to claim this issue and begin a fun, rewarding experience contributing to Zulip!

    Here's some tips to get you off to a good start:

    As you work on this issue, you'll also want to refer to the Zulip code contribution guide, as well as the rest of the developer documentation on that site.

    See you on the other side (that is, the pull request side)!

  4. Fahdmoh01 commented on Oct 1, 2023

    @Fahdmoh01

    @i-ky does the Rate limit has to do with the message_limit?

  5. i-ky commented on Oct 1, 2023

    @i-ky
    ContributorAuthor

    @i-ky does the Rate limit has to do with the message_limit?

    Sorry, I am not familiar with Zulip's internals. What is message_limit you are talking about?

  6. Fahdmoh01 commented on Oct 1, 2023

    @Fahdmoh01

    @i-ky does the Rate limit has to do with the message_limit?

    Sorry, I am not familiar with Zulip's internals. What is message_limit you are talking about?

    message_limit is a variable inside the Ratelimit class of the zulip python api. where do I go to ask for further clarification for this issue?

  7. i-ky commented on Oct 1, 2023

    @i-ky
    ContributorAuthor

    I can only clarify what I propose to be changed from a python-zulip-api user's perspective, how it is to be changed from python-zulip-api perspective is a different matter.

  8. timabbott commented on Oct 1, 2023

    @timabbott
    SponsorMember

    This need to be done as an option -- some clients might very much not want to have sleeps of this form be part of what might happen.

    I suppose there's also a question of whether we want the semantics to be to automatically retry the operation that failed due to the rate limit, or something else.

    We also need to be cautious in implementing documenting this sort of thing to make sure we don't end up with bugged clients hitting the server exactly as often as the rate limits allow - that can generate a lot more useless load than something that doesn't retry. Probably this is not too hard to manage.

  9. zulipbot commented on Oct 14, 2023

    @zulipbot
    Member

    @Fahdmoh01 You have been unassigned from this issue because you have not made any updates for over 14 days. Please feel free to reclaim the issue if you decide to pick up again. Thanks!

  10. 45 remaining items

  11. zulipbot commented on Oct 9, 2026

    @zulipbot
    Member

    @devnishantt You have been unassigned from this issue because you have not made any updates for over 14 days. Please feel free to reclaim the issue if you decide to pick up again. Thanks!

  12. devnishantt commented on Oct 9, 2026

    @devnishantt
    Collaborator

    Still working on this. The PR is up and waiting for review:
    #924

    Happy to revise if a reviewer asks for changes.

  13. devnishantt commented on Oct 14, 2026

    @devnishantt
    Collaborator

    @zulipbot claim

    PR is already open and waiting for review:
    #924

  14. zulipbot commented on Oct 24, 2026

    @zulipbot
    Member

    @devnishantt You have been unassigned from this issue because you have not made any updates for over 14 days. Please feel free to reclaim the issue if you decide to pick up again. Thanks!

  15. Aditya-XR commented on Nov 14, 2026

    @Aditya-XR
    Collaborator

    @zulipbot claim

  16. zulipbot commented on Nov 14, 2026

    @zulipbot
    Member

    Welcome to Zulip, @Aditya-XR! By picking up a Zulip issue, you're promising to do your best to follow Zulip's contributing guidelines. Neglecting to do so wastes maintainer time, and may result in being banned from contributing to Zulip.

    To get started:

    1. Work through all the "Prior to picking up your first issue" sections of the Zulip contributor guide.
    2. Post a comment here describing your plan for how to approach this issue. Before you claim an issue, you should be confident that you will be able to tackle it effectively.
    3. Accept the invite to collaborate on this repository at https://github.com/zulip/python-zulip-api/invitations. To avoid filling your inbox, we recommend unwatching this repository.

    The issue will be assigned to you when all three steps have been completed. If you get stuck, you can always @zulipbot abandon this issue, and pick a different one.

    If someone else claims this issue while you're working through the checklist, no worries! You can contribute by providing feedback on their pull request. If you’ve made good progress in understanding part of the codebase, you can also find another “help wanted” issue in the same area to work on.

  17. Aditya-XR commented on Nov 14, 2026

    @Aditya-XR
    Collaborator

    Here's my plan for tackling this based on the earlier discussion in #908:

    1. Add an opt-in auto_retry_rate_limits: bool = False flag to Client.__init__ so existing callers that expect do_api_query to return the RATE_LIMIT_HIT error dict immediately aren't blocked by default.
    2. In Client.do_api_query, check for res.status_code == 429 when self.auto_retry_rate_limits is enabled, parse the Retry-After header (falling back to 1.0s if it's missing or invalid), sleep for that duration, and retry the request.
    3. Add unit tests in zulip/tests/test_rate_limit.py mocking session.request and time.sleep to cover the default behavior, retrying with Retry-After, and the fallback when the header is missing/malformed.

    I've opened #946 with this implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions