Python: Backoff decoration not catching Error

Python: Backoff decoration not catching Error

我正在尝试使用 tweepy 来处理 Twitter 的 api。我打算使用 backoff 轻松实现指数退避来处理速率限制错误。但是,退避似乎不会在发生速率限制错误时捕获它们。这是我的代码:

    @backoff.on_exception(
        backoff.expo,
        tweepy.error.RateLimitError,
    )
    def page_followers(self, user, page_limit=-1):
      for page in tweepy.Cursor(self._api.followers, id=user.id).pages(page_limit):
           yield page

我的理解是,如果在应用 backoff.expo 后抛出 RateLimitError,退避应该重试。

知道我做错了什么吗?

**编辑以修复标题

它可能会捕获错误,但它达到了最大重试次数,之后您将看到 RateLimitError 异常。使用 tweepy 的内置等待机制可能效果更好:

self._api = tweepy.API(auth, wait_on_rate_limit=True)