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

StreamingClient: rate limit implementation incorrect #1986

Closed
deboomce opened this issue Oct 19, 2022 · 4 comments
Closed

StreamingClient: rate limit implementation incorrect #1986

deboomce opened this issue Oct 19, 2022 · 4 comments
Labels
Bug This is regarding a bug with the library Documentation This is regarding the library's documentation Duplicate This is a duplicate Question This is a question

Comments

@deboomce
Copy link

The BaseStream class checks the 420 HTTP error code, while it should be 429.

if resp.status_code == 420:

Also: the wait_on_rate_limit argument of StreamingClient is misleading, because it only impacts the add_rules and delete_rules methods. It has no impact on the filter or sample methods.

Related to this: how does a rate limit exactly work for a stream? Apparently you can make 50 requests per 15 minutes to the stream endpoint, but what does this mean exactly in the context of a stream?

@TrustyJAID
Copy link

TrustyJAID commented Oct 19, 2022

It's probably worth mentioning that in twitter's v1.1 streaming API the rate limit error code was 420. In the v2 Streaming API the rate limit code changed to 429.

Edit: After some more digging the socket read timeout has changed as well. v1.1 suggests using a 90 second read timeout while v2 suggests a 20 seconds read timeout. Currently the code uses the 90 second read timeout for all streaming endpoints.

@Harmon758 Harmon758 added Bug This is regarding a bug with the library Question This is a question Duplicate This is a duplicate Documentation This is regarding the library's documentation labels Oct 22, 2022
@Harmon758
Copy link
Member

This is partially a duplicate of #1982.

It's probably worth mentioning that in twitter's v1.1 streaming API the rate limit error code was 420. In the v2 Streaming API the rate limit code changed to 429.

Correct, I must have missed the change/difference when I implemented streaming for Twitter API v2.

Also: the wait_on_rate_limit argument of StreamingClient is misleading, because it only impacts the add_rules and delete_rules methods. It has no impact on the filter or sample methods.

This is a separate documentation issue arising from the fact that StreamingClient also subclasses BaseClient.
I'll work on improving that documentation presently.

Related to this: how does a rate limit exactly work for a stream? Apparently you can make 50 requests per 15 minutes to the stream endpoint, but what does this mean exactly in the context of a stream?

Each time you connect to the stream is a request being made to the endpoint.
There's also a limit in terms of the number of active (redundant/simultaneous) connections.

Edit: After some more digging the socket read timeout has changed as well. v1.1 suggests using a 90 second read timeout while v2 suggests a 20 seconds read timeout. Currently the code uses the 90 second read timeout for all streaming endpoints.

Good catch. I hadn't noticed that yet.
I'll work on a fix for that presently.

Harmon758 added a commit to Harmon758/tweepy that referenced this issue Oct 22, 2022
@Harmon758
Copy link
Member

Harmon758 commented Oct 22, 2022

Edit: After some more digging the socket read timeout has changed as well. v1.1 suggests using a 90 second read timeout while v2 suggests a 20 seconds read timeout. Currently the code uses the 90 second read timeout for all streaming endpoints.

Good catch. I hadn't noticed that yet.
I'll work on a fix for that presently.

This should be resolved with 3a71c9e now.

Harmon758 added a commit to Harmon758/tweepy that referenced this issue Oct 22, 2022
@Harmon758
Copy link
Member

Also: the wait_on_rate_limit argument of StreamingClient is misleading, because it only impacts the add_rules and delete_rules methods. It has no impact on the filter or sample methods.

This is a separate documentation issue arising from the fact that StreamingClient also subclasses BaseClient.
I'll work on improving that documentation presently.

This should be resolved with 7f0d587 (Tweepy's 3000th commit 🎉) now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This is regarding a bug with the library Documentation This is regarding the library's documentation Duplicate This is a duplicate Question This is a question
Projects
None yet
Development

No branches or pull requests

3 participants