【问题标题】:Rate limit exceeded in tweepytweepy 中超出速率限制
【发布时间】:2017-04-09 11:30:34
【问题描述】:

我在使用 tweepy 时遇到了限制问题。每次运行脚本时,我都会收到速率限制超出错误。我需要知道有什么方法可以知道在发生速率限制超出错误之前我可以执行多少个请求。

【问题讨论】:

    标签: twitter tweepy


    【解决方案1】:

    Tweepy 提供对速率限制 API 的访问。

    来自their documentation

    import tweepy
    
    consumer_key        = 'a'
    consumer_secret     = 'b'
    access_token        = 'c'
    access_token_secret = 'd'
    
    # OAuth process, using the keys and tokens
    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)
    
    # Creation of the actual interface, using authentication
    api = tweepy.API(auth)
    
    # Show the rate Limits
    print api.rate_limit_status()
    

    然后,您将看到所有可用速率限制的列表以及您剩余的通话次数。

    例如:

    { "rate_limit_context" : { "access_token" : "1234" },
      "resources" : { "account" : { "/account/login_verification_enrollment" : { "limit" : 15,
                  "remaining" : 15,
                  "reset" : 1411295469
                },
              "/account/settings" : { "limit" : 15,
                  "remaining" : 15,
                  "reset" : 1411295469
                },
              "/account/update_profile" : { "limit" : 15,
                  "remaining" : 15,
                  "reset" : 1411295469
                },
              "/account/verify_credentials" : { "limit" : 15,
                  "remaining" : 15,
                  "reset" : 1411295469
                }
    

    【讨论】:

      【解决方案2】:

      可以在 Twitter API 文档中找到速率限制:

      https://dev.twitter.com/docs/rate-limiting/1#rest

      【讨论】:

        猜你喜欢
        • 2013-12-31
        • 1970-01-01
        • 2022-08-19
        • 2015-10-20
        • 2017-02-28
        • 1970-01-01
        • 1970-01-01
        • 2014-12-15
        • 1970-01-01
        相关资源
        最近更新 更多