I've been working with the tweepy library for a bit, but I've come into this problem where .add_rules()
will always give me this Error 429: "This stream is currently at the maximum allowed connection limit."
This is the code I'm using which is causing this error
client = tweepy.StreamingClient(bearer_token=TWITTER_BEARER_TOKEN)
client.add_rules(tweepy.StreamRule("(from:kingerman88 OR from:KingerTester) -is:reply)") #errors here
print("Bot Online!")
client.filter(expansions=['author_id', 'in_reply_to_user_id'], user_fields=["id", "name", "username"])
I've tried resetting my the Bearer token a few times as well as changing the StreamRule, however nothing seems to be working. The only thread I could find about this on google was in regards to a twitter outage a year ago. Any help would be appreciated!
So I ended up figuring out what was wrong.
Apparently once created StreamRules
exist attached to your twitter application indefinitely (until removed explicitly)
Meaning that every time I had changed my stream rule, it added it to the app keeping the old rules. This also explains some of the unexpected behavior of my app. Wish this was better documented.
I added these extra few lines of code before adding the rules
client = tweepy.StreamingClient(bearer_token=TWITTER_BEARER_TOKEN)
# Delete previous rules as they exist indefinitely until deleted
previousRules = client.get_rules().data
if previousRules:
client.delete_rules(previousRules)
client.add_rules(tweepy.StreamRule("(from:kingerman88 OR from:KingerTester) -is:reply)")
client.filter(expansions=['author_id', 'in_reply_to_user_id'], user_fields=["id", "name", "username"])