skip to Main Content

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


  1. sleep_on_rate_limit is not a valid parameter for initializing API.

    So how i fix the "rate limit reached error. sleeping for…" error without this parameter???

    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.

    Login or Signup to reply.
  2. 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):

    def authenticating(credential):
    print('nnfunction>>>>>authenticating')
     
    """   
    █ █▄░█
    █ █░▀█    
    """
        # credential         • <dictionary>                 ○ its keys will be used to authenticate
        
    """
    █▀█ █░█ ▀█▀
    █▄█ █▄█ ░█░
    """
        # api                • <class 'tweepy.api.API'>     ○ authenticated api
    
    auth = tweepy.OAuthHandler(credential["api_key"],
                               credential["api_secret"])
    
    auth.set_access_token(credential["access_token"],
                          credential["access_token_secret"])
    
    api = tweepy.API(auth,
                     wait_on_rate_limit=True,
                     wait_on_rate_limit_notify=True)
    
    print(render(f'welcome,', font="slick", background='transparent'))
    print(render(f'{str(api.me().screen_name)}!', font="block", background='transparent')) 
    # prints name of authenticated user in large font 
    
    print('nfunction<<<<<authenticatingnn')
    return api
    

    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 =)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search