CezmiChef
CezmiChef

Reputation: 53

Tweepy Rate Errorr

I try infinity loop for check all tweets but if i use this codes

import tweepy
    import time
    no = 1
    a = no
    consumer_key = 'X'
    consumer_secret = 'X'
    access_token = 'X-X'
    access_token_secret = 'X'

    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)

    api = tweepy.API(auth, wait_on_rate_limit=False)
    timeline = api.user_timeline(count = 3)
    for t in timeline:
        api.destroy_status(t.id)
    time.sleep(9)
    while no == a:
        public_tweets = api.home_timeline()
        for tweet in public_tweets:
            tweet.text
            print tweet.text
            if tweet.text == "1":
                print "One"
                for t in timeline:
                    api.destroy_status(t.id)
                break
            if tweet.text == "0":
                print "Zero"
                for t in timeline:
                    api.destroy_status(t.id)            
                break   

error:

Traceback (most recent call last):
  File "test.py", line 21, in <module>
    public_tweets = api.home_timeline()
  File "/usr/local/lib/python2.7/dist-packages/tweepy/binder.py", line 245, in _call
    return method.execute()
  File "/usr/local/lib/python2.7/dist-packages/tweepy/binder.py", line 227, in execute
    raise RateLimitError(error_msg, resp)
tweepy.error.RateLimitError: [{u'message': u'Rate limit exceeded', u'code': 88}]

I want to infinity loop (like 15-20min) for check data all time How can i edit tweepy files or delete rate limit files

Upvotes: 2

Views: 1746

Answers (1)

Sandeep Hukku
Sandeep Hukku

Reputation: 399

There is a limit on the number of tweets you can get in a particular time interval i would suggest using a try catch block to handle the error.

c = public_tweets
while True:
try:
    tweet = c.next()
    # Insert into db
except tweepy.TweepError:
    time.sleep(60 * 15)
    continue
except StopIteration:
    break

Upvotes: 3

Related Questions