【问题标题】:tweepy error Failed to send request WSAECONNABORTEDtweepy 错误 发送请求失败 WSAECONNABORTED
【发布时间】:2016-04-19 22:38:38
【问题描述】:

我正在尝试收集用户关注者的完整列表。该用户拥有超过 100,000 名关注者。下面是我正在使用的代码。该代码返回几千个关注者,但随后出现错误“tweepy.error.TweepError: Failed to send request: (10053, 'WSAECONNABORTED')。我使用的是 Windows 机器。

auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

api = tweepy.API(auth, wait_on_rate_limit=True)

# get the followers' screen names 

for user in tweepy.Cursor(api.followers, screen_name="xxxx", count = 200).items():
    print user.screen_name

【问题讨论】:

    标签: python tweepy


    【解决方案1】:

    对于这么多关注者来说,这个过程可能需要相当长的时间。 10小时或更长的时间。在此期间出现某种错误的可能性很大,并且由于您没有以任何方式处理错误,因此每次弹出任何内容时您都可以重新开始。

    Twitter 使用游标来允许分页。换句话说,如果您知道脚本失败时当前光标是什么,则可以从上次中断的地方继续。

    使用这个来跟踪光标:

        current_cursor = user.iterator.next_cursor
    

    将其打印出来,或将其写入某个文件中,这样当脚本失败时,您可以调用:

    for user in tweepy.Cursor(api.followers, screen_name="xxxx", count = 200, cursor=current_cursor).items():
    

    这应该可以让您从中断的地方继续。 Original solution posed for a different problem.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-24
      • 1970-01-01
      • 2019-02-25
      • 2017-10-29
      • 2022-12-10
      • 2020-04-06
      • 2016-02-22
      相关资源
      最近更新 更多