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

feature idea - track internal ratelimiting #470

Open
jvanasco opened this issue Nov 7, 2017 · 2 comments
Open

feature idea - track internal ratelimiting #470

jvanasco opened this issue Nov 7, 2017 · 2 comments

Comments

@jvanasco
Copy link
Contributor

jvanasco commented Nov 7, 2017

Has anyone considered tracking ratelimits within Twython, to avoid hitting their API when it will most-likely fail? We have a lot of code that does it externally. I want to avoid network trips that won't work.

@michaelhelmick
Copy link
Collaborator

You can use get_application_rate_limit_status to get your applications current rate limit status. You can also except on TwythonRateLimitError or access the rate limiting header (https://github.com/ryanmcgrath/twython/blob/c9026247ee03bc8b22750a87ecf6425094ca77ee/docs/usage/advanced_usage.rst#access-headers-of-previous-call)

@jvanasco
Copy link
Contributor Author

jvanasco commented Nov 8, 2017

Let me clarify: we use all those techniques right now to populate a dict associated with the connection, that tracks the ratelimiting for each endpoint.

so a request for a timeline will set in our tracking dict the limit/remaining/reset timers for that endpoint (available via the last headers). before making a call, I check that dict to ensure it's likely to succeed and/or reset the timer. If the request is likely to fail, I raise a ratelimit error. this avoids hitting the server for very-likely failure situations. this also lets us check to see if we have any requests left before hitting the API, so we can cycle in another token if handy.

this is all done outside of twython though... and would likely be better written and maintained if the community at-large were interested in it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants