2017-01-20 7 views
0

Стараюсь петля бесконечности для проверки всех твитов, но если я использую эти кодыTweepy Оценить Errorr

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

Существует ограничение на количество твитов, которые вы можете получить за определенный промежуток времени, я бы предложил использовать блок catch try для обработки t он ошибается.

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

Traceback (самый последний вызов последнего): Файл "test.py", строка 16, в public_tweets = api.home_timeline() Файл «/usr/local/lib/python2.7/dist -packages/tweepy/binder.py ", строка 245, в _call return method.execute() Файл" /usr/local/lib/python2.7/dist-packages/tweepy/binder.py ", строка 227, in execute raise RateLimitError (error_msg, resp) tweepy.error.RateLimitError: [{u'message ': u'Rate limit above', u'code ': 88}] – CezmiChef