3
votes

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?

1

1 Answers

6
votes

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)