Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add automatic handling of RATE_LIMIT_HIT errors#858

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
tanmayg06 wants to merge1 commit intozulip:main
base:main
Choose a base branch
Loading
fromtanmayg06:fix/Handle_RATE_LIMIT_HIT

Conversation

tanmayg06
Copy link

This PR adds automatic handling of RATE_LIMIT_HIT errors in the Zulip API client. When a rate limit error is encountered, the client will now automatically wait for the specified period (from the Retry-After header if available) and retry the request, rather than requiring each application to implement this logic separately.

Fixes: The issue where applications need to implement their own rate limit handling logic when using the Zulip API client.

Changes include:

  1. Enhanceddo_api_query method to detect RATE_LIMIT_HIT errors
  2. Added logic to extract and use the Retry-After header value
  3. Implemented automatic retry mechanism with appropriate sleep duration
  4. Added fallback to existing error retry mechanism when no Retry-After header is provided
  5. Added comprehensive tests for the new functionality
  6. Updated README.md with documentation about the automatic rate limit handling

Code example of the implementation:

# Handle rate limiting automaticallyifjson_result.get("result")=="error"andjson_result.get("code")=="RATE_LIMIT_HIT":retry_after=None# Check for Retry-After header (in seconds)if"Retry-After"inres.headers:try:retry_after=int(res.headers["Retry-After"])except (ValueError,TypeError):pass# If we have a valid retry_after value, sleep and retryifretry_afterandretry_after>0:ifself.verbose:print(f"Rate limit hit. Retrying after{retry_after} seconds...")time.sleep(retry_after)continue# If no valid retry_after header, use a default backoffeliferror_retry(" (rate limited)"):continue

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@tanmayg06@zulipbot

[8]ページ先頭

©2009-2025 Movatter.jp