【问题标题】:Tweepy Rate ErrorrTweepy 速率错误
【发布时间】:2017-06-04 23:51:49
【问题描述】:

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

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 文件或删除速率限制文件

【问题讨论】:

    标签: python python-2.7 twitter tweepy tweets


    【解决方案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
    

    【讨论】:

    • Traceback(最近一次调用最后):文件“test.py”,第 16 行,在 public_tweets = api.home_timeline() 文件“/usr/local/lib/python2.7/ dist-packages/tweepy/binder.py”,第 245 行,在 _call 返回 method.execute() 文件“/usr/local/lib/python2.7/dist-packages/tweepy/binder.py”,第 227 行,在执行 raise RateLimitError(error_msg, resp) tweepy.error.RateLimitError: [{u'message': u'Rate limit exceeded', u'code': 88}]
    猜你喜欢
    • 1970-01-01
    • 2022-08-19
    • 1970-01-01
    • 2014-12-15
    • 1970-01-01
    • 2020-06-09
    • 1970-01-01
    • 2014-12-20
    • 2013-12-31
    相关资源
    最近更新 更多