在tweepy中使用光标处理速率限制异常

2024-05-10 11:24:23 发布

您现在位置:Python中文网/ 问答频道 /正文

在使用游标对象遍历跟随者列表时,我试图找到处理速率限制的正确方法。以下是我正在尝试的:

while True:
    try:
        for follower in tweepy.Cursor(api.followers, id=root_usr).items():
            print(follower.id)
    except tweepy.TweepError:
        # hit rate limit, sleep for 15 minutes
        print('Rate limited. Sleeping for 15 minutes.')
        time.sleep(15 * 60 + 15)
        continue
    except StopIteration:
        break

这可能是不正确的,因为异常将使for循环重新从头开始。在处理速率限制问题的同时,迭代所有root_usr的追随者的正确方法是什么


Tags: 对象方法idfor速率usrsleeproot