【问题标题】:Tweepy implementation to avoid Twitter rate limiter (python)避免 Twitter 速率限制器的 Tweepy 实现(python)
【发布时间】:2018-05-12 17:57:40
【问题描述】:

我正在尝试执行以下代码并收到“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) 命令失败。谁能帮帮我?

【问题讨论】:

    标签: python api twitter tweepy rate-limiting


    【解决方案1】:

    查看我的推特爬虫,我使用了“wait_on_rate_limit”和“wait_on_rate_limit_notify:https://github.com/Sy-Muzammil/Tweet-Crawlers/blob/master/geo_country.py

    【讨论】:

      猜你喜欢
      • 2019-08-23
      • 1970-01-01
      • 2022-08-19
      • 1970-01-01
      • 2014-02-14
      • 1970-01-01
      • 2019-04-01
      • 2013-12-31
      • 1970-01-01
      相关资源
      最近更新 更多