I don’t have much experience with API’s, much less this one with Twitter. I’m trying to resolve a error called "rate limit reached error. sleeping for…" in Python, trying to use the command sleep_on_rate_limit=True
, in the variable api
but an error is showing in the terminal, which I don’t know the reason or how to solve. Help me guys love u.
Error:
__init__() got an unexpected keyword argument 'sleep_on_rate_limit'
Code:
auth = tweepy.OAuthHandler(consumerkey, consumerkey_secret)
auth.set_access_token(acesstoken, acesstoken_secret)
api = tweepy.API(auth, wait_on_rate_limit=True, sleep_on_rate_limit=True)
2
Answers
sleep_on_rate_limit
is not a valid parameter for initializingAPI
.That’s a warning that you’re being rate limit by Twitter’s API and that Tweepy is automatically sleeping the necessary amount of time for you (since you have
wait_on_rate_limit
set). It is not an error.sleep_on_rate_limit is a parameter used by another lib other than tweepy. If you are using tweepy, the correspondent parameter is wait_on_rate_limit. They behave alike! Here’s an auth function I made for my retweet bot that is clean running since last year (please read after the code block):
P.s.: pay attention to the last twitter api version (v2) released on August 2021. I had troubles to authenticate by tweepy because of this parameter, and I believe the cause is linked to this new twitter API. Be sure to use a tweepy version released before the v2 twitter api or you will face unexpected and unexplainable errors. The most recent tweepy version pre-v2 is the 3.10.0. They will sure correct the problems for the next releases but for now, some precaution to not break your apps would be good.
Hope it helps you someway =)