Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tweepy rate limit exceeded when retrieving user timeline

I am trying to get tweets from a list of Twitter users using Tweepy's user_timeline module. However I keep getting the error message saying 'Rate limit exceeded'. I have read Twitter's documentation on rate limiting and am pretty sure I haven't exceeded it.

Excerpt of my code:

auth = tweepy.OAuthHandler(apikey, apisecret)
auth.set_access_token(AccessToken, AccessTokenSecret)
api = tweepy.API(auth)

user_list = [] #a list of 10 users
for user in user_list:
    tweets=tweepy.Cursor(api.user_timeline,id=user).items(10)

I also printed out tweepy's api.rate_limit_status and as expected, it shows the limit for user_timeline has been exceeded. But Twitter's documentation says the limit is 180 per 15 minutes window. And I don't think I have exceeded that.

'/statuses/user_timeline':{  
        'reset':1438149614,
        'limit':180,
        'remaining':0

Can anyone help?

like image 814
cirnelle Avatar asked Nov 28 '25 10:11

cirnelle


1 Answers

When you establish your API instance include the wait_on_rate_limit parameter (The docs show, it defaults to False). You can also add the notify parameter so you know when you're approaching the limit. http://docs.tweepy.org/en/latest/api.html

api = tweepy.API(auth, wait_on_rate_limit=True)
like image 175
Kevin Avatar answered Nov 30 '25 02:11

Kevin