Provide RateLimit info #167
Replies: 3 comments 10 replies
-
Hi. Typically when you are rate-limited exception will be raised. The exception provides access to the XrpcError instance and response headers. In headers, you can find information about limits. I guess there is no way to receive headers without reaching the limit. |
Beta Was this translation helpful? Give feedback.
-
Seems like it would be best to proactively limit yourself if you are getting close to rate limits. Could/should I make this an Request For Enhancement (RFE)? |
Beta Was this translation helpful? Give feedback.
-
Hello. I prepared simple example of override method that gives you access to response headers (which contains rate limits). class RateLimitedClient(Client):
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self._limit = self._remaining = self._reset = None
def get_rate_limit(self):
return self._limit, self._remaining, self._reset
def _invoke(self, *args, **kwargs):
response = super()._invoke(*args, **kwargs)
self._limit = response.headers.get('ratelimit-limit')
self._remaining = response.headers.get('ratelimit-remaining')
self._reset = response.headers.get('ratelimit-reset')
return response Usage: client = RateLimitedClient()
client.login(os.environ['USERNAME'], os.environ['PASSWORD'])
post = client.get_timeline()
print(client.get_rate_limit()) |
Beta Was this translation helpful? Give feedback.
-
Hi there, I'm currently working on debugging why my bot hits rate limit issues and I don't know how to access this info via atproto.
I see logging.debug messages on certain calls will print out this info:
But I don't know how to query this
RateLimit
info via the atproto library.Beta Was this translation helpful? Give feedback.
All reactions