Tweepy Rate Errorr

时间:2017-01-20 04:21:20

标签: python python-2.7 twitter tweepy tweets

我尝试无限循环检查所有推文,但如果我使用此代码

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   

错误:

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}]

我希望无限循环(如15-20分钟)一直检查数据 如何编辑tweepy文件或删除速率限制文件

1 个答案:

答案 0 :(得分:1)

在特定时间间隔内您可以获得的推文数量有限制我建议使用try catch块来处理错误。

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