error.py 938 B

12345678910111213141516171819202122232425262728293031323334
  1. # Tweepy
  2. # Copyright 2009-2010 Joshua Roesslein
  3. # See LICENSE for details.
  4. from __future__ import print_function
  5. import six
  6. class TweepError(Exception):
  7. """Tweepy exception"""
  8. def __init__(self, reason, response=None, api_code=None):
  9. self.reason = six.text_type(reason)
  10. self.response = response
  11. self.api_code = api_code
  12. Exception.__init__(self, reason)
  13. def __str__(self):
  14. return self.reason
  15. def is_rate_limit_error_message(message):
  16. """Check if the supplied error message belongs to a rate limit error."""
  17. return isinstance(message, list) \
  18. and len(message) > 0 \
  19. and 'code' in message[0] \
  20. and message[0]['code'] == 88
  21. class RateLimitError(TweepError):
  22. """Exception for Tweepy hitting the rate limit."""
  23. # RateLimitError has the exact same properties and inner workings
  24. # as TweepError for backwards compatibility reasons.
  25. pass