Tweepy 实现以避免 Twitter 速率限制器 (python)

Tweepy implementation to avoid Twitter rate limiter (python)

我正在尝试执行以下代码并收到“88”错误,也复制在下面。我已经删除了 Twitter 帐户句柄,但我包含了 25 个帐户句柄,每个帐户句柄都有大约 3k-80k 的关注者(可能平均约为 20k)。

import time
import tweepy
import csv
from itertools import zip_longest

auth = tweepy.OAuthHandler('', '')
auth.set_access_token('', '')

api = tweepy.API(auth)

accounts = [25 twitter account handles here as strings]

numberOfAccts = len(accounts)
d = [[''],[''],[''],[''],[''],[''],[''],[''],[''],[''],[''],[''],[''],[''],[''],[''],[''],[''],[''],[''],[''],[''],[''],[''],['']]

with open('FollowerIDLists.csv', 'a', newline="") as f:
    #writer = csv.writer(f)
    for i in range(0, numberOfAccts):
        print(accounts[i])
        ids = []
        for page in tweepy.Cursor(api.followers_ids, screen_name=accounts[i]).pages():
            ids.extend(page)
            time.sleep(60)
        d[i] = ids
    export_data = zip_longest(*d, fillvalue = '')
    wr = csv.writer(f)
    wr.writerow(accounts)
    wr.writerows(export_data)
f.close()

这是错误:

Traceback (most recent call last):
  File "C:\Users\USER\Desktop\composeFollowerIDLists.py", line 30, in <module>
    for page in tweepy.Cursor(api.followers_ids, screen_name=accounts[i]).pages():
  File "C:\Users\USER\AppData\Local\Programs\Python\Python36-32\lib\site-packages\tweepy\cursor.py", line 49, in __next__
    return self.next()
  File "C:\Users\USER\AppData\Local\Programs\Python\Python36-32\lib\site-packages\tweepy\cursor.py", line 75, in next
    **self.kargs)
  File "C:\Users\USER\AppData\Local\Programs\Python\Python36-32\lib\site-packages\tweepy\binder.py", line 245, in _call
    return method.execute()
  File "C:\Users\USER\AppData\Local\Programs\Python\Python36-32\lib\site-packages\tweepy\binder.py", line 227, in execute
    raise RateLimitError(error_msg, resp)
tweepy.error.RateLimitError: [{'message': 'Rate limit exceeded', 'code': 88}]

我听说避免速率限制器的正确方法是使用 'wait_on_rate_limit' 和 'wait_on_rate_limit_notify' 的某种组合,但我不知道如何在上面实现这些。如您所见,我尝试使用 time.sleep(60) 命令失败。谁能帮我一把?

查看我使用的推文爬虫 'wait_on_rate_limit' 和 'wait_on_rate_limit_notify : https://github.com/Sy-Muzammil/Tweet-Crawlers/blob/master/geo_country.py