xdevplatform / Twitter-API-v2-sample-code

Sample code for the Twitter API v2 endpoints
https://developer.twitter.com/en/docs/twitter-api/getting-started/about-twitter-api
Apache License 2.0
2.61k stars 967 forks source link

Filtered stream example can cause 429 error #140

Open paulvav opened 9 months ago

paulvav commented 9 months ago

Describe the bug

The example code for filtered streams (python) does not properly close the stream. Upon using this code repeatedly it is possible to open many streams past your limit, and not be able to disconnect them. This can lock you out of using the Twitter filtered stream API for however long it takes the twitter server to disconnect the streams.

I have been currently been locked out for a day, and receive this response every time I try to reconnect.

'{"title":"ConnectionException","detail":"This stream is currently at the maximum allowed connection limit.","connection_issue":"TooManyConnections","type":"https://api.twitter.com/2/problems/streaming-connection"}'

To Reproduce Run example code multiple times until you receive the 429 error.

Expected behavior Example code should include a disconnect, so that developers are aware of this possibility. Or a way to force the twitter server to disconnect all current open connections should be released.

Additional context Add any other context about the problem here.